[Bug 15395] New: Allow correct handling of plural translation
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 Bug ID: 15395 Summary: Allow correct handling of plural translation Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: ASSIGNED Severity: enhancement Priority: P5 - low Component: I18N/L10N Assignee: julian.maurice@biblibre.com Reporter: julian.maurice@biblibre.com QA Contact: testopia@bugs.koha-community.org CC: frederic@tamil.fr In response to Frédéric's comment on bug 15206 (http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15206#c33) I wanted to see what could be done to handle translation of plural in Koha. This is my attempt to manage translation in both Perl code and templates -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 --- Comment #1 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 45797 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=45797&action=edit Bug 15395: Allow correct handling of plural translation Locale::Maketext does not allow correct handling of plural translation for languages that have more than one plural forms. Locale::Messages does. So Koha::I18N is now a wrapper around Locale::Messages, just like Locale::TextDomain, and export the same symbols as Locale::TextDomain. You can refer to documentation of Locale::TextDomain to know how to use exported subroutines. The PO file moves from misc/translator/po/xx-XX-messages.po to misc/translator/po/xx_XX/LC_MESSAGES/Koha.po and now needs to be compiled to MO in order to be used by Koha. Compilation of PO file is done by running: ./translate install xx-XX Remove dependency to Locale::Maketext and Locale::Maketext::Lexicon Add dependency to Locale::Messages Test plan: 1. Open a .pl script or .pm module with your favorite text editor 2. Add 'use Koha::I18N;' in the beginning of file 3. Use one of the subroutines exported by Koha::I18N and be sure to have a way to visualize the result (pass result to the template for example, or simply warn and watch the log file) 4. cd misc/translator && ./translate update fr-FR # try other languages 5. Open misc/translator/po/fr_FR/LC_MESSAGES/Koha.po and translate your string(s) You will need to change the "Plural-Forms" header. See https://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html 6. ./translate install fr-FR 7. Use your web browser to go to the page that should display the translation, change language and verify the translation is correct Example usage: __("Hi") __x("Hi {name}", name => 'Bob') __n("item", "items", $num_items) __nx("one item", "{count} items", $num_items, count => $num_items) __p("Bibliographic record", "item") -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 --- Comment #2 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 45798 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=45798&action=edit Bug 15395: Plural translations in templates Provides a way to handle translation of plural forms in templates Add Template::Toolkit plugin for Koha::I18N Use like this: [%# USE the plugin and define some macros %] [% PROCESS 'i18n.inc' %] [%# tn is the equivalent of __n %] [%# macro names can't start with underscore, t is for "translate" %] [% tn('item', 'items', num_items) %] Extraction of strings from templates is a bit complicated and use Template::Parser and PPI. Template is compiled into Perl code and then analyzed by PPI. It is slow, but should be correct even with complex constructions. Add dependency to PPI Test plan: 1. Open a template file (.tt or .inc) with your favorite text editor 2. Add the PROCESS directive mentioned above in the beginning of file 3. Use one of the t* macros defined in i18n.inc. They are used like their "__" equivalent, with one difference: the 'x' variants take a hashref instead of a hash as last parameter 4. cd misc/translator && ./translate update fr-FR 5. Open misc/translator/po/fr_FR/LC_MESSAGES/Koha.po and translate your string(s) 6. ./translate install fr-FR 7. Use your web browser to go to the page that should display the translation, change language and verify the translation is correct -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 --- Comment #3 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 45799 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=45799&action=edit Bug 15395: Example usage of I18N Template::Toolkit plugin -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |http://bugs.koha-community. | |org/bugzilla3/show_bug.cgi? | |id=15206 CC| |jonathan.druart@bugs.koha-c | |ommunity.org -- You are receiving this mail because: You are watching all bug changes.
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15395 --- Comment #4 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 46337 --> http://bugs.koha-community.org/bugzilla3/attachment.cgi?id=46337&action=edit Bug 15395: Add plural translation capabilities to JS files It adds Javascript equivalent of Koha::I18N's exported subroutines, and they are used the same way. String extraction is done only on *.js files and require gettext 0.19 (available in Debian stable, and also in wheezy-backports) It adds Javascript library Gettext.js for handling translation and a Perl script po2json to transform PO file into JSON. Gettext.js and po2json both come from Locale::Simple. There are several tools named po2json. It's simpler to integrate this one into Koha than to check if the good one is installed on the system. Locale::Simple is not needed. To avoid polluting the global namespace too much, this patch also introduce a global JS object named Koha and add some stuff in Koha.i18n Test plan: 1. Add a translatable string in a JS file. For example, add this: alert(__nx("There is one item", "There are {count} items", 3, {count: 3})); to staff-global.js 2. cd misc/translator && ./translate update fr-FR 3. Open misc/translator/po/fr_FR/LC_MESSAGES/Koha.po, verify that your string is present, and translate it 4. cd misc/translator && ./translate install fr-FR 5. (Optional) Verify that koha-tmpl/intranet-tmpl/prog/fr-FR/js/locale_data.js exists and contains your translation 6. Open your browser on the staff main page, change language and verify that the message is translated 7. Repeat 1-6 on OPAC side -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org