stable

Clone or download

Read-only

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