https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43843
--- Comment #2 from Frédéric Demians <[email protected]> --- Created attachment 208419 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208419&action=edit Bug 43843: Replace Gettext.js with Tannin When the Content-Security-Policy is enabled and the interface is translated, Gettext.js builds the plural function of the Plural-Forms header with "new Function". The CSP doesn't allow 'unsafe-eval', so the browser throws an EvalError, Koha.i18n is never defined, and every translated string (__, __n, __x...) throws a TypeError: DataTables tables are not initialized, etc. This patch replaces Gettext.js, a third-party script (bug 42577), with Tannin, which evaluates plural forms without eval. i18n.js keeps the Koha.i18n.gt object and its gettext, ngettext, pgettext and npgettext functions, now based on Tannin, so __(), __n(), __p(), __np() and their __x variants don't change. The locale_data.js files don't change either: i18n.js removes the msgid_plural that misc/translator/po2json puts before the translations, as Tannin expects the translations only. So the installed translations work without being reinstalled. Only the translated templates must be updated, as usual, to load Tannin instead of Gettext.js. An untranslated plural string now uses the English plural forms: with Gettext.js, it used the plural forms of the language, and could show the English singular for several items (for instance "Show 1 claim" for 101 claims in Japanese, which has a single plural form). Compared with Gettext.js on the messages-js translations of fr-FR, fr-CA, de-DE, pl-PL, ru-RU, cs-CZ, ar-Arab and ja-Jpan-JP, for every string and counts from 0 to 101, the translations are the same, except for the untranslated plural strings above. Test plan: 1. Install a translation, for instance fr-FR: cd misc/translator && perl translate install fr-FR 2. Add it to the OPACLanguages and StaffInterfaceLanguages system preferences. 3. Check that the CSP is enabled for the OPAC in koha-conf.xml: <content_security_policy><opac><csp_mode>enabled</csp_mode> Restart Plack and flush memcached. 4. In the OPAC, in French, open a record detail page (opac-detail.pl) and open the browser console: => The console shows "EvalError: Evaluating a string as JavaScript violates the following Content Security Policy directive..." and "TypeError: Cannot read properties of undefined (reading 'gt')". => The items table is not a DataTables table: no sorting. 5. Apply the patches and update the translated templates: cd misc/translator && perl translate install fr-FR Reload the page (clear the browser cache if needed): => No error in the console. => The items table can be sorted, and its texts are in French. 6. Switch the OPAC to English: no error, no change. 7. In the staff interface, in French and in English, check pages using translated JavaScript strings, for instance the checkouts table of a patron: no error, the texts are translated. 8. Check that the About page, Licenses tab, lists Tannin. 9. Run the Cypress test: yarn cypress run --spec t/cypress/integration/i18n_spec.ts -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected] website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
