Project

General

Profile

Translating » History » Version 23

Dominic Cleal, 04/17/2013 04:01 AM

1 6 Lukas Zapletal
h1. Translating for contributors
2 1 Lukas Zapletal
3 7 Lukas Zapletal
h2. General tips
4
5
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. 
6
7
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
8
9
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:
10
11
 _('Compute resource') -> "Compute Resource"
12
13
 _('ComputeResource|Description') -> "Description"
14
15
Several models have prefixes in the form something/ or Something:: - you can ignore these. Example:
16
17
 _('Audited/adapters/active record/audit') -> "Audit"
18
19
 _('Audited::Adapters::ActiveRecord::Audit|Associated name') -> "Associated Name"
20
21 6 Lukas Zapletal
h2. Using Transifex
22
23
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).
24
25
Read the tips bellow if you want to start translating now.
26 1 Lukas Zapletal
27 2 Lukas Zapletal
h2. Manually
28
29
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:
30
31
  foreman# rake gettext:pack
32 1 Lukas Zapletal
33 2 Lukas Zapletal
or
34 1 Lukas Zapletal
35 7 Lukas Zapletal
  foreman# make -C locale check all-mo
36 2 Lukas Zapletal
37 1 Lukas Zapletal
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.
38
39
More info about contributing your translation directly is on our [[Contribute]] wiki page. 
40
41 6 Lukas Zapletal
h1. Translating for developers
42 1 Lukas Zapletal
43 15 Lukas Zapletal
h2. Extracting strings
44
45
There are several rules to follow when marking strings for translations with _("") and similar functions:
46
47
 * To translate a string use _("My string")
48
 * To translate string with a parameter use _("String with param: %25s") %25 param
49
 * To translate string with more than one parameters do not use _("Params: %25s and %25s") %25 [param1, param2] which is translator-unfriendly
50
 * Therefore for more than one parameters use _("Params: %25{a} and %25{b}") %25 {:a => foo, :b => bar}
51
 * To mark something for translation (but not translate) use N_("String")
52
 * 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.
53
 * 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.
54
 * 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
55
 * 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).
56
 * Strings get extracted into ./locale/foreman.pot file, model and column names are in ./locale/model_attributes.rb
57
 * Additional Rails strings are in ./config/locale - there is a script to update those from Rails I18N git (branch 3-x).
58
 * For more info go here: http://www.yotabanana.com/hiki/ruby-gettext-howto.html
59
60
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
61
62
  foreman# rake locale:find
63
64 21 Lukas Zapletal
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:
65
66
  foreman# make -C locale check -j4
67
  foreman# make -C locale clean
68 15 Lukas Zapletal
69
h2. Generating gettext translate tables
70
71
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.
72
73
To generate gettext MO files, you can do either
74
75
  foreman# rake gettext:pack
76
77
or
78
79
  foreman# make -C locale
80
81
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.
82
83 8 Lukas Zapletal
h2. Adding new language
84 6 Lukas Zapletal
85 2 Lukas Zapletal
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):
86 12 Lukas Zapletal
87 3 Lukas Zapletal
  # cp locale/foreman.pot locale/xx/foreman.po
88 6 Lukas Zapletal
  # vim locale/xx/foreman.po
89
90 1 Lukas Zapletal
Then pull Rails translation strings from upstream 3-x branch:
91 12 Lukas Zapletal
92
  # cd config/locale
93
  # touch xx.yml
94
  # ./update.sh
95
96
And add the language to Transifex and Zanata using their web interfaces.
97 2 Lukas Zapletal
98 6 Lukas Zapletal
h2. How to pull translations
99 1 Lukas Zapletal
100 4 Lukas Zapletal
To get updated translations from Transifex you will need account there (https://www.transifex.com) and the tx cli tool.
101
102
On Fedora:
103
104
  # yum -y install transifex-client gettext make intltool
105
106
On Debian:
107
108
  # apt-get install transifex-client gettext make intltool-debian
109
110
Then configure your account:
111
112
  $ cat ~/.transifexrc
113
  [https://www.transifex.net]
114
  hostname = https://www.transifex.net
115
  username = <your_username>
116
  password = <your_password>
117
  token = <should be empty>
118
119
And then prepare new topic branch (because the following command will make new commits to your git repo):
120
121
  git checkout -b update-translations
122
123
Finally do the translation pull
124
125
  make -C locale tx-update
126
127
And then you can push changes.
128
129
  git push ...
130 9 Lukas Zapletal
131
h2. Not translated
132
133
Some parts are (yet) not translated. These include:
134
135 10 Lukas Zapletal
 * all JavaScript resources (components etc)
136 9 Lukas Zapletal
 * permission names
137
 * predefined role names
138
 * predefined user names
139 20 Dominic Cleal
 * names of settings?
140 11 Dominic Cleal
 * default bookmark names (active, disabled etc)
141
 * INTERNAL auth method
142 13 Lukas Zapletal
 * audit entries
143 14 Dominic Cleal
 * will_paginate (Dom working on this)
144 16 Dominic Cleal
 * reorder the More submenus alphabetically?
145 18 Dominic Cleal
 * predefined install media names ("mirror")
146
 * predefined partition table names
147 19 Dominic Cleal
 * template types/kinds
148 1 Lukas Zapletal
 * predefined template names
149 20 Dominic Cleal
 * "Clear" tooltip in scoped_search
150 22 Dominic Cleal
 * any external assert gems, e.g. SPICE HTML 5 console, noVNC?
151 23 Dominic Cleal
 * Puppet log messages, log levels
152
 * column names used in scoped_search
153 10 Lukas Zapletal
154
Some items from the list above will never be translated due to technical reasons or to avoid confusion.