From 34c07a58f8cdbe9a4c36b93b7c680837499f3018 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Thu, 9 Apr 2020 16:50:55 +0200 Subject: [PATCH] Bug 25099: Sending a LANG variable to plug-in template MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- Koha/Plugins/Base.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm index 9751b194a2..295e351c86 100644 --- a/Koha/Plugins/Base.pm +++ b/Koha/Plugins/Base.pm @@ -163,12 +163,12 @@ sub get_template { authnotrequired => 1, } ); - $template->param( CLASS => $self->{'class'}, METHOD => scalar $self->{'cgi'}->param('method'), PLUGIN_PATH => $self->get_plugin_http_path(), PLUGIN_DIR => $self->get_plugin_dir(), + LANG => C4::Languages::getlanguage($self->{'cgi'}), ); return $template; -- 2.39.5