published on 18 August 2017

If your daily language isn't English, you've probably noticed that the output from supported Puppet modules is displayed in English — and only in English. That's about to change. We are now making changes so that other languages can be available on the Forge. This is part of our internationalization effort to support end users whose first language is not English.

If you're writing a module and you want to make it available in multiple languages, you need to decorate strings that are externalized — that is, displayed to the person using the module. I will illustrate how this works with the MySQL module, by using a solution based on RuboCop.

RuboCop

RuboCop is a static code analyzer that is used to enforce best-practice style guidelines documented in the Ruby Style Guide. It helps to keep code consistent and readable while supporting contributions from multiple authors. It can also be used to help developers identify syntactic errors. RuboCop runs against the Ruby code in a module — that is, against code in the lib/ folder. (Note that it does not run against Puppet DSL.) It is already enabled for Vox Pupuli modules and the RuboCop template was developed by the Puppet developer experience team for use in the Puppet Development Kit (PDK), and will become the default recommendation for new modules.

The various checks that RuboCop performs on code are known as “cops.” RuboCop allows custom “cops” to be defined. We are going to create a new custom cop that will identify strings that should be marked for translation in the module and decorate those strings, so they can be extracted for translation. The goal is to decorate all the warning and error strings that are displayed to the end user by the module.

How to run RuboCop

RuboCop is run by typing the command the ‘bundle exec rubocop’ command, as illustrated in the screenshot below, which runs the command for the contents of the ‘lib’ folder. This identifies strings that need to be decorated.


Image of How to run RuboCop

Is it also possible for RuboCop to auto-correct the strings that it finds. This can be performed by passing in the -a parameter, as illustrated below. This should be used with with caution, as it’s noted as experimental.


Image of How to run RuboCop

How this affects you

We are starting to externalize strings in the MySQL module, with the aim to add Japanese translations in the near future. Contributors to the MySQL module will notice that it conforms to the RuboCop configuration, as demonstrated by this pull request. RuboCop will now be run by Travis and available as a Rake task in the Puppet Spec Helper.

Next steps

RuboCop with our custom cop will be enabled on other supported modules in the future in order to have their user-visible strings decorated for translation.

Davin Hanlon is the product owner for modules at Puppet.

Learn more

Share via:

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.