Project

General

Profile

Actions

Translating » History » Revision 25

« Previous | Revision 25/73 (diff) | Next »
Lukas Zapletal, 04/22/2013 09:03 AM


Translating for contributors

General tips

It is important not to change punctuation and whitespace. For example if the English string is "blah." it must be translated as "xyz." with the dot at the end. The same for an extra space - e.g. "blah " must be "xyz ". Although we try to eliminate all the extra spaces, there are rare cases where we need them. There is a checker (pofilter) which is executed regularly by developers to catch and fix all these types of mistakes.

There are model names in the translation strings, you can get the full list here: https://github.com/lzap/foreman/blob/develop/locale/model_attributes.rb

These model names are in two formats: "Model name" (name of the database table) and "Modelname|Column name" for column name. Here are few examples how to translate them:

_('Compute resource') -> "Compute Resource"
_('ComputeResource|Description') -> "Description"

Several models have prefixes in the form something/ or Something:: - you can ignore these. Example:

_('Audited/adapters/active record/audit') -> "Audit"
_('Audited::Adapters::ActiveRecord::Audit|Associated name') -> "Associated Name"

Using Transifex

Go to https://www.transifex.com/projects/p/foreman and register/login. Then you can use the Transifex interface to do all translations. The project on Transifex automatically updates when we add new strings into git. Foreman team regularly downloads new translations to the develop branch in git as well, therefore there is no action needed when you finish with translations. It will be pulled eventually (e.g. before the next release).

Read the tips bellow if you want to start translating now.

Manually

If you prefer, you can edit PO files directly using your preferred editor. Please make sure the encoding of the files is UTF-8. It is also recommended to test your translations before submitting a Pull Request on the github using either:

foreman# rake gettext:pack

or

foreman# make -C locale check all-mo

The above command should not print any error message. Also you should start Foreman UI and see if your translations do fit (sometimes longer strings can wrap or even break the UI). If you start Foreman in the production mode, you need to do one of the above commands every time you change your translation. In the development mode, you only need to restart Foreman to see the changes.

More info about contributing your translation directly is on our Contribute wiki page.

Translating for developers

Extracting strings

There are several rules to follow when marking strings for translations with _("") and similar functions:

  • To translate a string use _("My string")
  • To translate string with a parameter use _("String with param: %25s") %25 param
  • To translate string with more than one parameters do not use _("Params: %25s and %25s") %25 [param1, param2] which is translator-unfriendly
  • Therefore for more than one parameters use _("Params: %25{a} and %25{b}") %25 {:a => foo, :b => bar}
  • To mark something for translation (but not translate) use N_("String")
  • To use plural form use s_("One", "Two", number) - note this function always accepts three parameters as the base language is usually English but translators are able to define as many plural forms as they need.
  • Plural forms are usually used with one parameter, do not forget to add trailing parameter to it: n_("%25s minute", "%25s minutes", @param) %25 @param
  • Do not break strings with newlines because then the strings have many whitespace and it looks confusing for translators like "blah \\n blah". If you must separate string on several lines, you can use HEREDOC or you can contatenate strings like "line1" + "line2" because Ruby Gettext detects them both.
  • If you want to leave a note to the translator, just drop a comment before the string in the format of # TRANSLATORS: your comment here
  • Note that all HEREDOC strings are automatically extracted, when adding API documentation descriptions via HEREDOC, leave a message to translators not to translate these (API documentation will not be translated at the moment).
  • Strings get extracted into ./locale/foreman.pot file, model and column names are in ./locale/model_attributes.rb
  • All our form helpers have been enriched and understand model and column names - if the field is in the model_attribute.rb (above), it does not need to be translated explicitly (e.g. text_f f, :name is enough and will be translated to "Modelname|Name")
  • Additional Rails strings are in ./config/locale - there is a script to update those from Rails I18N git (branch 3-x).
  • For more info go here: http://www.yotabanana.com/hiki/ruby-gettext-howto.html

From time to time it is good to extract strings and update translations with incoming strings, so translators are able to work on them. We usually do this before releases, but it is good idea to do this on a weekly/monthly basis. For string extractions, please do not use rake gettext:find but use

foreman# rake locale:find

because it also extracts model names and columns and filters them plus it adds some notes to translators (see locale:find_model rake task). Although locale:find does some checks for malformed strings, it is good idea to run additional pofilter check which is able to find many mistakes like trailing whitespace and others:

foreman# make -C locale check -j4
foreman# make -C locale clean

Generating gettext translate tables

For production environment, you need to compile PO files into binary translate tables (MO files). This is not needed for development or test environments as in these modes Foreman reads PO files directly.

To generate gettext MO files, you can do either

foreman# rake gettext:pack

or

foreman# make -C locale

Both tools generate the same result, the latter is a bit faster and allows additional checks (see locale/Makefile targets). If you install from distribution packages, you do not need to run this because everything has been pre-compiled already.

Adding new language

Adding new language into Foreman is easy. You need to take two steps - first of all create new gettext PO file as a copy from POT and edit the header (at least set plural configuration):

  1. cp locale/foreman.pot locale/xx/foreman.po
  2. vim locale/xx/foreman.po

Then pull Rails translation strings from upstream 3-x branch:

  1. cd config/locale
  2. touch xx.yml
  3. ./update.sh

And add the language to Transifex and Zanata using their web interfaces.

How to pull translations

To get updated translations from Transifex you will need account there (https://www.transifex.com) and the tx cli tool.

On Fedora:

  1. yum -y install transifex-client gettext make intltool

On Debian:

  1. apt-get install transifex-client gettext make intltool-debian

Then configure your account:

$ cat ~/.transifexrc
[https://www.transifex.net]
hostname = https://www.transifex.net
username = <your_username>
password = <your_password>
token = <should be empty>

And then prepare new topic branch (because the following command will make new commits to your git repo):

git checkout -b update-translations

Finally do the translation pull

make -C locale tx-update

And then you can push changes.

git push ...

Not translated

Some parts are (yet) not translated. These include:

  • all JavaScript resources (components etc)
  • permission names
  • predefined role names
  • predefined user names
  • names of settings?
  • default bookmark names (active, disabled etc)
  • INTERNAL auth method
  • audit entries
  • will_paginate (Dom working on this)
  • reorder the More submenus alphabetically?
  • predefined install media names ("mirror")
  • predefined partition table names
  • template types/kinds
  • predefined template names
  • "Clear" tooltip in scoped_search
  • any external assert gems, e.g. SPICE HTML 5 console, noVNC?
  • Puppet log messages, log levels
  • column names used in scoped_search

Some items from the list above will never be translated due to technical reasons or to avoid confusion.

Updated by Lukas Zapletal almost 11 years ago · 25 revisions