-
Notifications
You must be signed in to change notification settings - Fork 12
Puppet module i18n: Ruby code
Starting with Ruby code, you are going to use RuboCop to aid you with string decoration. As you have included the gems, they will be enabled by default.
Run RuboCop to return your rule violations, which will point you in the right direction for string decoration.
The RuboCop run can be altered by adding certain flags to it, the primary ones being -a
which causes it to attempt to autocorrect the decorations and --display-cop-names
which causes additional information regarding the exact cop/rule that the code has violated.
At this point in time, only warn and error methods are supported, all others must be located manually.
# Standard Run
bundle exec rake rubocop
# Autofix Run
bundle exec rake rubocop:auto_correct
# Additional Information Run
bundle exec rubocop lib --display-cop-names
See below for examples of decorated code, with the original line shown above it:
# Simple String
raise ArgumentError, "Unmatched double quote"
raise ArgumentError, _('Unmatched double quote')
# Concatenated String
raise ArgumentError, "Unmatched " + "double quote"
raise ArgumentError, _('Unmatched double quote')
# Interpolated String
raise ArgumentError, "Unmatched double quote: #{str.inspect}" if garbage
raise ArgumentError, _('Unmatched double quote: %{str_inspect}') % { str_inspect: str.inspect } if garbage
# Multiline String
raise ArgumentError, "Unmatched " \
"double quote"
raise ArgumentError, _('Unmatched double quote')
Now that you have decorated the code, run the following command to generate the .pot
file:
bundle exec rake gettext:pot
This command creates a file called #{module_name}.pot (puppetlabs-accounts.pot) inside the locales
folder.
Once this file is generated, check for any duplicates as these can cause errors further down in the code when we merge the separate .pot
files.