[Bug 39564] New: Enable runtime translations for plugins (Koha::I18N)
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Bug ID: 39564 Summary: Enable runtime translations for plugins (Koha::I18N) Change sponsored?: --- Product: Koha Version: Main Hardware: All OS: All Status: NEW 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: f.demians@tamil.fr, jonathan.druart@gmail.com This is an attempt to have translatable plugins (like bug 37472) but using Koha::I18N (runtime translations) See also bug 37472 comment 11 and bug 37472 comment 8 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #1 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 180642 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=180642&action=edit Bug 39564: Enable runtime translations for plugins (Koha::I18N) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #180642|0 |1 is obsolete| | --- Comment #2 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 180643 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=180643&action=edit Bug 39564: Enable runtime translations for plugins (Koha::I18N) This solution uses gettext's textdomain feature to allow plugins to use Koha::I18N for their own translations. Basically we have one textdomain per plugin and we bind the directory where a plugin store its translations (.mo files) to its textdomain. Plugins have to specify the textdomain like this: __d('MyPlugin', 'string to translate') or, if within a template: [% I18N.td('MyPlugin', 'string to translate') %] This patches adds several functions to Koha::I18N: __d, __dn, __dp, __dnp, __dx, __dnx, __dpx, and __dnpx and their template equivalents in Koha::Template::Plugin::I18N It also moves some code for string extraction from gulpfile.js to misc/translator/xgettext-perl and misc/translator/xgettext-js for easier use by plugins authors. (Note that, even if there is a misc/translator/xgettext-js script, this patch does not add support for JS translations in plugins) By default a plugin named Koha::Plugin::Foo will have a textdomain 'Koha-Plugin-Foo'. It can be changed by overriding method locale_textdomain. By default the directory bound to the textdomain will be Koha/Plugin/Foo/locale. It can be changed by overriding method locale_dir. This directory should contain one subdirectory for each language, and each language subdirectory should contain an LC_MESSAGES subdirectory which should contain a <textdomain>.mo file. It should look like this: Koha/ Plugin/ Foo/ locale/ fr_FR/ LC_MESSAGES/ Koha-Plugin-Foo.mo de_DE/ LC_MESSAGES/ Koha-Plugin-Foo.mo ... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff --- Comment #3 from Julian Maurice <julian.maurice@biblibre.com> --- Example plugin here : https://gitlab.com/jajm/koha-plugin-i18n-example Test plan: 1. Apply the patch 2. Install the example plugin and restart koha 3. Enable fr-FR language for the staff interface. 4. Go to Admin > Plugins and run the example plugin's tool. 5. Switch between en and fr-FR to see the changes. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Marion Durand <marion.durand@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |marion.durand@biblibre.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dcook@prosentient.com.au -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Jonathan Druart <jonathan.druart@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matt.blenkinsop@openfifth.c | |o.uk, | |paul.derscheid@lmscloud.de, | |pedro.amorim@openfifth.co.u | |k, tomascohen@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #4 from Jonathan Druart <jonathan.druart@gmail.com> --- Did you investigate a way to prevent the addition of the new methods? It would be nice to use the existing ones and deal with the domain in Koha::Plugins or Koha::I18N. We could guess the caller and set the domain depending on it. Not totally sure how we would make that work, but I’m curious, did you already ask yourself that question? :) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #5 from Julian Maurice <julian.maurice@biblibre.com> --- (In reply to Jonathan Druart from comment #4)
Did you investigate a way to prevent the addition of the new methods?
Actually I started without the new methods but I figured it would be nice to make these two things customizable. So yes, it's totally doable. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #6 from Julian Maurice <julian.maurice@biblibre.com> --- (In reply to Julian Maurice from comment #5)
(In reply to Jonathan Druart from comment #4)
Did you investigate a way to prevent the addition of the new methods?
Actually I started without the new methods but I figured it would be nice to make these two things customizable. So yes, it's totally doable.
I may have read your comment too quickly. Are you talking about the __d* functions ? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #7 from Julian Maurice <julian.maurice@biblibre.com> --- (In reply to Julian Maurice from comment #6)
(In reply to Julian Maurice from comment #5)
(In reply to Jonathan Druart from comment #4)
Did you investigate a way to prevent the addition of the new methods?
[...]
I may have read your comment too quickly. Are you talking about the __d* functions ? For templates, the new methods can be avoided by writing something like this:
[% USE i18n = I18N('Example') %] [% i18n.t('string to translate') %] All that is needed is a `new` method in Koha::Template::Plugin::I18N that stores its textdomain parameter (within $self) so it can be used in t* methods. On the Perl side, it might not be that simple, as it would probably require keeping a "wrapper object" around (the wrapper object would change the default textdomain, call the appropriate function __*, then revert the default textdomain to its original value).
We could guess the caller and set the domain depending on it. I really don't like subroutines that change their behaviour depending on the caller. It makes them more difficult to debug and test.
-- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Patch doesn't apply CC| |lucas@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #180643|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 --- Comment #8 from Julian Maurice <julian.maurice@biblibre.com> --- Created attachment 191403 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=191403&action=edit Bug 39564: Enable runtime translations for plugins (Koha::I18N) This solution uses gettext's textdomain feature to allow plugins to use Koha::I18N for their own translations. Basically we have one textdomain per plugin and we bind the directory where a plugin store its translations (.mo files) to its textdomain. Plugins have to specify the textdomain like this: __d('MyPlugin', 'string to translate') or, if within a template: [% I18N.td('MyPlugin', 'string to translate') %] This patches adds several functions to Koha::I18N: __d, __dn, __dp, __dnp, __dx, __dnx, __dpx, and __dnpx and their template equivalents in Koha::Template::Plugin::I18N It also moves some code for string extraction from gulpfile.js to misc/translator/xgettext-perl and misc/translator/xgettext-js for easier use by plugins authors. (Note that, even if there is a misc/translator/xgettext-js script, this patch does not add support for JS translations in plugins) By default a plugin named Koha::Plugin::Foo will have a textdomain 'Koha-Plugin-Foo'. It can be changed by overriding method locale_textdomain. By default the directory bound to the textdomain will be Koha/Plugin/Foo/locale. It can be changed by overriding method locale_dir. This directory should contain one subdirectory for each language, and each language subdirectory should contain an LC_MESSAGES subdirectory which should contain a <textdomain>.mo file. It should look like this: Koha/ Plugin/ Foo/ locale/ fr_FR/ LC_MESSAGES/ Koha-Plugin-Foo.mo de_DE/ LC_MESSAGES/ Koha-Plugin-Foo.mo ... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39564 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Patch doesn't apply |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org