stable
Clone or download
request #9657: Tuleap goes gettext
This is a first commit to replace .tab based translations by GNUΒ GettextΒ one. To minimize changes, only two parts of Tuleap benefit from gettext. Tuleap Core =========== The first module which benefits from this change is the shortcuts modal help (press [?] in any Tuleap web page). The workflow is the following: - As a developer instead of: $GLOBALS['Language']->gettext('global', 'btn_submit'); write the following: _('Submit'); - Run `make generate-po` - Edit site-content/fr_FR/LC_MESSAGES/tuleap-core.po with your favorite editor (like poedit). We assume that teh editor generates for you a .mo for the saved .po file (like poedit), or run `make generate-mo`. - On the server, make sure that fr_FR locale is installed (`locale -a`). If it is not the case, run `localedef -i fr_FR -f UTF-8 fr_FR.UTF-8`. - `service httpd restart` to flush the cache of .mo and prevent a Segmentation fault of Apache (sic). Note: maybe we could use Weblate[1] in order to improve our translation workflow (ease contribution of other languages than English and French). This means that developers will only generate .pot file, and translator teams will update their .po based on this .pot file. Tuleap Plugins ============== The second module which benefits from this change is the proftpd plugin. The good news is that this is the same workflow as for the core. However to avoid clashes, and not pollute core with plugins stuff, plugins are using their own domain of strings. For example for the plugin Profpd, the domain (and .pot/.po files) will be named after 'tuleap-proftpd'. In order to distinguish in which domain gettext should look into, one should use dgettext('tuleap-proftpd', 'β¦') instead of _('β¦'). Of course in one plugin, you can use both _('β¦') and dgettext('tuleap-proftpd', 'β¦'). You can also use translation from other plugins, however they must exist beforehand (You cannot define a new string related to tracker in agiledashboard for example) and you must respect dependencies between plugins. As of today proftpd is hardcoded in generate-{po,mo}.sh files. We will introduce a nice loop when another plugin will switch to gettext. We should not be to clever ========================== Looking at all call to dgettext('tuleap-proftd', 'β¦'), the first things coming in mind is to use a constant so that we don't repeat ourselves: dgettext(proftpdPlugin::DOMAIN, 'β¦'). However this won't work. The command xgettext extracts strings without being able to interpret php constants or variables. We *need* to repeat ourselves. (Like before.) Arguments ========= .tab format for arguments ('$2 can haz $1 hamburgers', 4, 'John') is not anymore supported. We have to use sprintf: sprintf(_('%2$s can haz %1$s hamburgers'), 4, 'John') // John can haz 4 hamburgers See https://php.net/sprintf documentation for details. Mustache ======== Gettext in mustache is currently not supported. Recent version of the lib we use may help but we must upgrade the lib first. The difficult part for this case is that xgettext (the tool that parses source code and extracts strings to generate .pot file) is based on method invocations: gettext(), translate(), β¦ ; in mustache we will have things like this: {{_i18n}}Dylan is in the kitchen{{/_i18n}} which are not method invocations. For the record, there is a php lib[2] that can parse various file formats (js, twig, β¦). Maybe we will be able to write an extractor for mustache files. We will have to take into account the possibility to pass arguments. To be investigated later. /etc customizations =================== .tab system let administrators customize strings translation by putting files in /etc/tuleap/site-content. While this has the advantage to help promote the alm among users in the company by using common terms (e.g. "Delivery" instead of "File release system"), it may be the opportunity to think about another way to provide custom content (like custom color for the theme?). To be investigated later. Plurals ======= Unfortunately there is no plural management in Tuleap with .tab files. Therefore it is not introduced in this commit. When we will need plural, we will have to use ngettext and dngettext (and adapt extraction of strings in generate-po.sh β see --join-existing argument of xgettext). To be investigated later, if needed. ~~~ TL;DR: Usage of gettext produces a more readable code! [1] https://weblate.org/en/ [2] https://github.com/oscarotero/Gettext Change-Id: Iab49e258a52e875509fc6de81c7fe8c6c7de684b
Modified Files
Name | ||||
---|---|---|---|---|
M | Makefile | +6 | β0 | Go to diff View file |
M | plugins/proftpd/include/ProFTPd/Admin/AdminController.class.php | +23 | β13 | Go to diff View file |
M | plugins/proftpd/include/ProFTPd/Explorer/ExplorerController.class.php | +6 | β3 | Go to diff View file |
M | plugins/proftpd/include/ProFTPd/Presenter/AdminPresenter.class.php | +14 | β9 | Go to diff View file |
M | plugins/proftpd/include/ProFTPd/Presenter/ExplorerPresenter.class.php | +4 | β4 | Go to diff View file |
M | plugins/proftpd/include/ProftpdPluginDescriptor.class.php | +2 | β2 | Go to diff View file |
M | plugins/proftpd/include/proftpdPlugin.class.php | +4 | β2 | Go to diff View file |
M | plugins/proftpd/site-content/en_US/proftpd.tab | +0 | β24 | Go to diff View file |
A | plugins/proftpd/site-content/fr_FR/LC_MESSAGES/tuleap-proftpd.po | +85 | β0 | Go to diff View file |
M | plugins/proftpd/site-content/fr_FR/proftpd.tab | +0 | β24 | Go to diff View file |
A | plugins/proftpd/site-content/tuleap-proftpd.pot | +62 | β0 | Go to diff View file |
D | site-content/en_US/include/keyboard_navigation.tab | +0 | β31 | Go to diff View file |
A | site-content/fr_FR/LC_MESSAGES/tuleap-core.po | +105 | β0 | Go to diff View file |
D | site-content/fr_FR/include/keyboard_navigation.tab | +0 | β31 | Go to diff View file |
A | site-content/tuleap-core.pot | +89 | β0 | Go to diff View file |
M | src/utils/analyse_language_files.pl | +1 | β1 | Go to diff View file |
M | src/www/include/pre.php | +7 | β0 | Go to diff View file |
M | src/www/themes/FlamingParrot/keyboard_navigation/KeyboardNavigationModalPresenter.class.php | +30 | β30 | Go to diff View file |
M | tools/rpm/Makefile | +5 | β1 | Go to diff View file |
A | tools/utils/generate-mo.sh | +31 | β0 | Go to diff View file |
A | tools/utils/generate-po.sh | +61 | β0 | Go to diff View file |