Created attachment 77477 [details] [review] Bug 21156: 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 jessie, 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-messages-js.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 Signed-off-by: Marc Véron <veron@veron.ch>
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})); It looks like we already have a way of doing this with the format() syntax. Example: http://git.koha-community.org/gitweb/?p=koha.git;a=blob;f=koha-tmpl/intranet-tmpl/prog/en/includes/select2.inc;hb=705571a2b870fbb652ca210e32ee3e7ca050e75f#l45 How would plural translation work? Can you give examples for context and plurals?
(In reply to Katrin Fischer from comment #2) > 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})); > > It looks like we already have a way of doing this with the format() syntax. Variable substitution works the same way as format() but allows to give names to substitutions, to ease the work of translators (ex: "I like {food} and {drink}" is easier to read and translate than "I like %s and %s") > How would plural translation work? Can you give examples for context and > plurals? For plural translation, gettext will select the correct string based on the integer parameter (the 3rd for __n and __nx, the 4th for __np and __npx) and the Plural-Forms header in the PO file For instance, var count = <a positive integer> __n('item', 'items', count) In English, __n will return 'item' if count == 1, 'items' otherwise In French, __n will return 'exemplaire' if count == 0 or count == 1, 'exemplaires' otherwise, because Plural-Forms is "nplurals=2; plural=(n > 1); In Slovenian, __n can return up to 4 different strings, because Slovenian has 4 different "plural forms" The context is just another string to help disambiguation. Ex: __p('Bibliographic record', 'item') This will appear in the po file as msgctxt "Bibliographic record" msgid "item" And you can combine context and plural forms __np('Bibliographic record', 'item', 'items', count)
Created attachment 91976 [details] [review] Bug 21156: 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 jessie, 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-messages-js.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
*** Bug 4503 has been marked as a duplicate of this bug. ***
Created attachment 97345 [details] [review] Bug 21156: 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 jessie, 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-messages-js.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
Last rebase (from comment 4) contains a wrong conflict resolution.
Created attachment 97346 [details] [review] Bug 21156: 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 jessie, 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-messages-js.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 Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Looks good, and passes a few quick tests.. I'm going to give it an SO stamp, but would love to see someone more familiar with the translations process give it a once over. :)
This works well, but qa-tool shows an error: Processing files before patches |========================>| 7 / 7 (100.00%) Processing files after patches |===> | 1 / 7 (14.29%) An error occurred : Unmatched [ in regex; marked by <-- HERE in m/_\(\(?<string>[ <-- HERE ^\]*)\\)/ at /.../qa-test-tools/QohA/File/JS.pm line 29. Is this a false positive?
(In reply to Bernardo Gonzalez Kriegel from comment #10) > This works well, but qa-tool shows an error: > > Processing files before patches > |========================>| 7 / 7 (100.00%) > Processing files after patches > |===> | 1 / 7 (14.29%) > > An error occurred : Unmatched [ in regex; marked by <-- HERE in > m/_\(\(?<string>[ <-- HERE ^\]*)\\)/ at /.../qa-test-tools/QohA/File/JS.pm > line 29. > > Is this a false positive? Yes, definitely, I am going to open an issue.
(In reply to Jonathan Druart from comment #11) > (In reply to Bernardo Gonzalez Kriegel from comment #10) > > This works well, but qa-tool shows an error: > > > > Processing files before patches > > |========================>| 7 / 7 (100.00%) > > Processing files after patches > > |===> | 1 / 7 (14.29%) > > > > An error occurred : Unmatched [ in regex; marked by <-- HERE in > > m/_\(\(?<string>[ <-- HERE ^\]*)\\)/ at /.../qa-test-tools/QohA/File/JS.pm > > line 29. > > > > Is this a false positive? > > Yes, definitely, I am going to open an issue. https://gitlab.com/koha-community/qa-test-tools/issues/23
Created attachment 98535 [details] [review] Bug 21156: 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 jessie, 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-messages-js.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 Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Works well, translation is Ok and test message is displayed correctly. Current qa-tool error is a false positive.
(In reply to Jonathan Druart from comment #12) ... > > Yes, definitely, I am going to open an issue. > > https://gitlab.com/koha-community/qa-test-tools/issues/23 Good!
I'm going to take that second signoff from Bernardo as a PQA as the resident translation expert. I found no regressions in my own testing and am confident in the change.. Thanks everyone!
Nice work everyone! Pushed to master for 20.05
enhancement not pushed to 19.11.x branch
Correction- Pushed to 19.11.x branch for 19.11.04 Thanks martin!