Created attachment 163380 [details] [review] Bug 36357: Add Template::Toolkit filters for internationalization (I18N) This patch makes it possible to write in templates the following: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', count) %] [% 'singular with {var}' | tnx('plural with {var}', cnt, var = 'val') %] These filters are an alternative to the macros defined in i18n.inc. Some advantages: * They do not conflict with variables (see bug 36927) * They are always defined (no need to USE a plugin or PROCESS a file) i18n functions that takes a context argument (tp, tpx, tnp, tnpx) are deliberately not defined as filters. Because context is the first argument, this would require writing: [% 'context' | tp('message') %] Whereas we'd prefer to write: [% 'message' | tp('context') %] There are two ways to fix this: 1. Change the order of arguments in Koha::Template::Plugin::I18N and change the -k options in xgettext-tt2 (the msgid must be first), or 2. Use different keywords, and add them as -k options in xgettext-tt2 Test plan: 1. Find a template file that you can edit and where you can easily see the changes (for instance intranet-main.tt) 2. Add the following code: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', 1) %] [% 'singular with {var}' | tnx('plural with {var}', 2, var = 'val') %] 3. Run misc/translator/translate update fr-FR 4. Open misc/translator/po/fr-FR-messages.po, make sure you find those 4 new strings. Translate them. 5. Run misc/translator/translate install fr-FR 6. Restart Koha 7. Change the language in the interface. Verify that the strings are translated
Created attachment 163381 [details] [review] Bug 36357: Add Template::Toolkit filters for internationalization (I18N) This patch makes it possible to write in templates the following: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', count) %] [% 'singular with {var}' | tnx('plural with {var}', cnt, var = 'val') %] These filters are an alternative to the macros defined in i18n.inc. Some advantages: * They do not conflict with variables (see bug 36297) * They are always defined (no need to USE a plugin or PROCESS a file) i18n functions that takes a context argument (tp, tpx, tnp, tnpx) are deliberately not defined as filters. Because context is the first argument, this would require writing: [% 'context' | tp('message') %] Whereas we'd prefer to write: [% 'message' | tp('context') %] There are two ways to fix this: 1. Change the order of arguments in Koha::Template::Plugin::I18N and change the -k options in xgettext-tt2 (the msgid must be first), or 2. Use different keywords, and add them as -k options in xgettext-tt2 Test plan: 1. Find a template file that you can edit and where you can easily see the changes (for instance intranet-main.tt) 2. Add the following code: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', 1) %] [% 'singular with {var}' | tnx('plural with {var}', 2, var = 'val') %] 3. Run misc/translator/translate update fr-FR 4. Open misc/translator/po/fr-FR-messages.po, make sure you find those 4 new strings. Translate them. 5. Run misc/translator/translate install fr-FR 6. Restart Koha 7. Change the language in the interface. Verify that the strings are translated
Created attachment 163521 [details] [review] Bug 36357: Add Template::Toolkit filters for internationalization (I18N) This patch makes it possible to write in templates the following: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', count) %] [% 'singular with {var}' | tnx('plural with {var}', cnt, var = 'val') %] These filters are an alternative to the macros defined in i18n.inc. Some advantages: * They do not conflict with variables (see bug 36297) * They are always defined (no need to USE a plugin or PROCESS a file) i18n functions that takes a context argument (tp, tpx, tnp, tnpx) are deliberately not defined as filters. Because context is the first argument, this would require writing: [% 'context' | tp('message') %] Whereas we'd prefer to write: [% 'message' | tp('context') %] There are two ways to fix this: 1. Change the order of arguments in Koha::Template::Plugin::I18N and change the -k options in xgettext-tt2 (the msgid must be first), or 2. Use different keywords, and add them as -k options in xgettext-tt2 Test plan: 1. Find a template file that you can edit and where you can easily see the changes (for instance intranet-main.tt) 2. Add the following code: [% 'simple text' | t %] [% 'text with {var}' | tx(var = 'value') %] [% 'singular' | tn('plural', 1) %] [% 'singular with {var}' | tnx('plural with {var}', 2, var = 'val') %] 3. Run misc/translator/translate update fr-FR 4. Open misc/translator/po/fr-FR-messages.po, make sure you find those 4 new strings. Translate them. 5. Run misc/translator/translate install fr-FR 6. Restart Koha 7. Change the language in the interface. Verify that the strings are translated Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 163522 [details] [review] Bug 36357: Tidy xgettext-tt2.t Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 163523 [details] [review] Bug 36357: Tidy I18N.pm Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Created attachment 163524 [details] [review] Bug 36357: Add POD to Filters/I18N.pm Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Getting Can't locate object method "new" via package "Template::Filters" (perhaps you forgot to load "Template::Filters"?) at /kohadevbox/koha/C4/Templates.pm line 74
(In reply to Kyle M Hall from comment #7) > Getting > Can't locate object method "new" via package "Template::Filters" (perhaps > you forgot to load "Template::Filters"?) at /kohadevbox/koha/C4/Templates.pm > line 74 How do you get that ? I can't reproduce
Created attachment 163597 [details] [review] Bug 36357: Fix Template::Filters error Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(In reply to Julian Maurice from comment #8) > (In reply to Kyle M Hall from comment #7) > > Getting > > Can't locate object method "new" via package "Template::Filters" (perhaps > > you forgot to load "Template::Filters"?) at /kohadevbox/koha/C4/Templates.pm > > line 74 > > How do you get that ? I can't reproduce Odd. I was able to fix the error by adding "use Template::Filters" to Templates.pm!