[Bug 25099] New: Add lang from cookie to plugins template params
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Bug ID: 25099 Summary: Add lang from cookie to plugins template params Change sponsored?: Sponsored Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: trivial Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: nicolas.legrand@bulac.fr QA Contact: testopia@bugs.koha-community.org CC: kyle@bywatersolutions.com, severine.queune@bulac.fr, tomascohen@gmail.com Created attachment 102643 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=102643&action=edit The Mannequin plugin to test this Bug To make internationalised plugin, it may be useful to get the KohaOpacLanguage from Koha cookie. We could then branch an include template containing all strings in the page in a specific language à la Theke solutions (see https://gitlab.com/thekesolutions/plugins/koha-plugin-pay-via-paypal/-/blob/...) The idea is to have Koha/Plugin/Com/Something/Superplugin/i18n with lang_dialect.inc files. It contains a TOKENS hash with all the string you need for your plugin. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #1 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- Created attachment 102644 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=102644&action=edit Bug 25099: Add lang from cookie to plugins template params To make internationalised plugins, it may be useful to get the KohaOpacLanguage from Koha cookie. This patch adds the value of $cgi->cookie('KohaOpacLanguage') to a LANG variable which is sent to the template plugin. In your plugin, you can add a i18n directory containing lang[-DIALECT].inc files with a TOKENS hash like this: [% TOKENS = { PLUGIN_NAME = "Mannequin" PRESENTATION = "Voici un example d'outil." CLICK_ME = "Cliquez moi !" } %] The plugin template can then include such a lang[-DIALECT].inc with a hash containing all the plugin strings: [% TRY %] [% PROCESS "$PLUGIN_DIR/i18n/${LANG}.inc" %] [% CATCH %] [% PROCESS "$PLUGIN_DIR/i18n/default.inc" %] [% END %] The strings are then printed in the template with something like: [% TOKENS.PRESENTATION %] Test plan: 1. apply patch 2. install, enable and run BULAC Mannequin plugin 3. it should print stuff in english by default 4. install french French (fr-FR) 5. change you Koha lang to French 6. run again the plugin 7. ho là là! French! -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 didier <didier.gautheron@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |In Discussion CC| |didier.gautheron@biblibre.c | |om --- Comment #2 from didier <didier.gautheron@biblibre.com> --- Hi Using directly a raw cookie is generally unsafe. cf. https://bugs.koha-community.org/bugzilla3//show_bug.cgi?id=6629 C4::Languages::getlanguage(); is available and I believe its uses is fair game for plugins. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|In Discussion |RESOLVED Resolution|--- |INVALID --- Comment #3 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- (In reply to didier from comment #2)
Hi
Using directly a raw cookie is generally unsafe. cf.
https://bugs.koha-community.org/bugzilla3//show_bug.cgi?id=6629
C4::Languages::getlanguage();
is available and I believe its uses is fair game for plugins.
!!! You're totally right! Thanks! -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |--- Status|RESOLVED |REOPENED -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |In Discussion -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #4 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- So should we send a LANG variable to template with C4::Languages::getlanguage and create an “official way to do translations in plug-ins” or should anyone get along with what fits him most and use C4::Languages::getlanguage directly from its own plug-in? -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Add lang from cookie to |Sending a LANG variable to |plugins template params |template plug-in -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Sending a LANG variable to |Sending a LANG variable to |template plug-in |plug-in template -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rel_20_05_candidate CC| |martin.renvoize@ptfs-europe | |.com -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #5 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Nicolas Legrand from comment #4)
So should we send a LANG variable to template with C4::Languages::getlanguage and create an “official way to do translations in plug-ins” or should anyone get along with what fits him most and use C4::Languages::getlanguage directly from its own plug-in?
I agree with stashing the LANG variable like this, and also agree it should be done using getlanguages() as the PayPal plugin does, but in Base.pm. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #6 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- (In reply to Tomás Cohen Arazi from comment #5)
(In reply to Nicolas Legrand from comment #4)
So should we send a LANG variable to template with C4::Languages::getlanguage and create an “official way to do translations in plug-ins” or should anyone get along with what fits him most and use C4::Languages::getlanguage directly from its own plug-in?
I agree with stashing the LANG variable like this, and also agree it should be done using getlanguages() as the PayPal plugin does, but in Base.pm.
The only problem I see is that one should not reference C4 namespace in Koha namespace :). -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #7 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- Created attachment 104309 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=104309&action=edit Bug 25099: Sending a LANG variable to plug-in template To make internationalised plug-ins, it may be useful to get the lang from C4::Languages::getlanguage. This patch adds C4::Languages::getlanguage result to a LANG variable which is sent to the template plugin. In your plugin, you can add a i18n directory containing lang[-DIALECT].inc files with a TOKENS hash like this: [% TOKENS = { PLUGIN_NAME = "Mannequin" PRESENTATION = "Voici un example d'outil." CLICK_ME = "Cliquez moi !" } %] The plugin template can then include such a lang[-DIALECT].inc with a hash containing all the plugin strings: [% TRY %] [% PROCESS "$PLUGIN_DIR/i18n/${LANG}.inc" %] [% CATCH %] [% PROCESS "$PLUGIN_DIR/i18n/default.inc" %] [% END %] The strings are then printed in the template with something like: [% TOKENS.PRESENTATION %] Test plan: 1. apply patch 2. install, enable and run BULAC Mannequin plugin 3. it should print stuff in english by default 4. install french French (fr-FR) 5. change you Koha lang to French 6. run again the plugin 7. ho là là! French! Thanks to Tomàs Cohen and his pay via paypal plug-in from which most ideas in this patch are taken. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #102644|0 |1 is obsolete| | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|In Discussion |Needs Signoff -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #8 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- I let the QA team decide if C4::Languages::getlanguage called from Koha::Plugin::Base is legit or not :). -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #9 from Tomás Cohen Arazi <tomascohen@gmail.com> --- (In reply to Nicolas Legrand from comment #8)
I let the QA team decide if C4::Languages::getlanguage called from Koha::Plugin::Base is legit or not :).
That's not a problem, Nicolas. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Victor Grousset/tuxayo <victor@tuxayo.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #104309|0 |1 is obsolete| | --- Comment #10 from Victor Grousset/tuxayo <victor@tuxayo.net> --- Created attachment 104317 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=104317&action=edit Bug 25099: Sending a LANG variable to plug-in template To make internationalised plug-ins, it may be useful to get the lang from C4::Languages::getlanguage. This patch adds C4::Languages::getlanguage result to a LANG variable which is sent to the template plugin. In your plugin, you can add a i18n directory containing lang[-DIALECT].inc files with a TOKENS hash like this: [% TOKENS = { PLUGIN_NAME = "Mannequin" PRESENTATION = "Voici un example d'outil." CLICK_ME = "Cliquez moi !" } %] The plugin template can then include such a lang[-DIALECT].inc with a hash containing all the plugin strings: [% TRY %] [% PROCESS "$PLUGIN_DIR/i18n/${LANG}.inc" %] [% CATCH %] [% PROCESS "$PLUGIN_DIR/i18n/default.inc" %] [% END %] The strings are then printed in the template with something like: [% TOKENS.PRESENTATION %] Test plan: 1. apply patch 2. install, enable and run BULAC Mannequin plugin 3. it should print stuff in english by default 4. install french French (fr-FR) 5. change you Koha lang to French 6. run again the plugin 7. ho là là! French! Thanks to Tomàs Cohen and his pay via paypal plug-in from which most ideas in this patch are taken. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Victor Grousset/tuxayo <victor@tuxayo.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |victor@tuxayo.net Status|Needs Signoff |Signed Off --- Comment #11 from Victor Grousset/tuxayo <victor@tuxayo.net> --- ho là là ça marche! It works! -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #104317|0 |1 is obsolete| | --- Comment #12 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Created attachment 104374 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=104374&action=edit Bug 25099: Sending a LANG variable to plug-in template To make internationalised plug-ins, it may be useful to get the lang from C4::Languages::getlanguage. This patch adds C4::Languages::getlanguage result to a LANG variable which is sent to the template plugin. In your plugin, you can add a i18n directory containing lang[-DIALECT].inc files with a TOKENS hash like this: [% TOKENS = { PLUGIN_NAME = "Mannequin" PRESENTATION = "Voici un example d'outil." CLICK_ME = "Cliquez moi !" } %] The plugin template can then include such a lang[-DIALECT].inc with a hash containing all the plugin strings: [% TRY %] [% PROCESS "$PLUGIN_DIR/i18n/${LANG}.inc" %] [% CATCH %] [% PROCESS "$PLUGIN_DIR/i18n/default.inc" %] [% END %] The strings are then printed in the template with something like: [% TOKENS.PRESENTATION %] Test plan: 1. apply patch 2. install, enable and run BULAC Mannequin plugin 3. it should print stuff in english by default 4. install french French (fr-FR) 5. change you Koha lang to French 6. run again the plugin 7. ho là là! French! Thanks to Tomàs Cohen and his pay via paypal plug-in from which most ideas in this patch are taken. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords|rel_20_05_candidate |release-notes-needed Status|Signed Off |Passed QA --- Comment #13 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Passing QA, this works well and is a useful addition to the plugin architecture. We do however, need something for the release notes and even better some plugin developer documentation somewhere.. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #14 from Nicolas Legrand <nicolas.legrand@bulac.fr> --- (In reply to Martin Renvoize from comment #13)
Passing QA, this works well and is a useful addition to the plugin architecture.
We do however, need something for the release notes
What about: “[Bug 25099] Sending a LANG variable to plug-in template”?
and even better some plugin developer documentation somewhere..
There isn't much documentation apart from “take a look at kitchen sink” right?. I can make some pull requests with internationalized kitchen sink? -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #15 from didier <didier.gautheron@biblibre.com> --- (In reply to Nicolas Legrand from comment #14)
(In reply to Martin Renvoize from comment #13)
Passing QA, this works well and is a useful addition to the plugin architecture.
We do however, need something for the release notes
What about: “[Bug 25099] Sending a LANG variable to plug-in template”?
and even better some plugin developer documentation somewhere..
There isn't much documentation apart from “take a look at kitchen sink” right?. I can make some pull requests with internationalized kitchen sink?
Add the first Koha version with LANG available? -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #16 from Katrin Fischer <katrin.fischer@bsz-bw.de> --- I think updating kitchen sink would be a good start. I'd love more general documentaiton than 'read the code' still, but at least there it's all in one place for now. See also: https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Pushed to master Version(s)| |20.05.00 released in| | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 --- Comment #17 from Martin Renvoize <martin.renvoize@ptfs-europe.com> --- Nice work everyone! Pushed to master for 20.05 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Joy Nelson <joy@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Pushed to master |Pushed to stable CC| |joy@bywatersolutions.com Version(s)|20.05.00 |20.05.00, 19.11.06 released in| | --- Comment #18 from Joy Nelson <joy@bywatersolutions.com> --- Backported to 19.11.x for 19.11.06 -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 claire.hernandez@biblibre.com <claire.hernandez@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |claire.hernandez@biblibre.c | |om -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |nicolas.legrand@bulac.fr |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@bugs.koha-c | |ommunity.org Keywords|release-notes-needed | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Nicolas Legrand <nicolas.legrand@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |Make it easier to build release notes| |internationalised plug-in | |by sending a LANG variable | |to the plug-in template. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25099 Arthur Suzuki <arthur.suzuki@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=37472 -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org