From 773f76a2e9cad0c8d40ef196ae5afa5341c6b535 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 22 Jun 2018 16:44:39 +0200 Subject: [PATCH] Bug 15395: Fix translation when text contains non-ASCII characters msgid, msgid_plural and msgctxt need to be utf8-encoded Also, remove call to Locale::Messages->select_package which is not needed anymore --- Koha/I18N.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Koha/I18N.pm b/Koha/I18N.pm index e2b88b7beb..44c47132ff 100644 --- a/Koha/I18N.pm +++ b/Koha/I18N.pm @@ -50,7 +50,6 @@ sub init { my $cache = Koha::Cache::Memory::Lite->get_instance(); my $cache_key = 'i18n:initialized'; unless ($cache->get_from_cache($cache_key)) { - Locale::Messages->select_package('gettext_pp'); my @system_locales = grep { chomp; not (/^C/ || $_ eq 'POSIX') } qx/locale -a/; if (@system_locales) { # LANG needs to be set to a valid locale, @@ -86,24 +85,34 @@ sub init { sub __ { my ($msgid) = @_; + $msgid = Encode::encode_utf8($msgid); + return _gettext(\&gettext, [ $msgid ]); } sub __x { my ($msgid, %vars) = @_; + $msgid = Encode::encode_utf8($msgid); + return _gettext(\&gettext, [ $msgid ], %vars); } sub __n { my ($msgid, $msgid_plural, $count) = @_; + $msgid = Encode::encode_utf8($msgid); + $msgid_plural = Encode::encode_utf8($msgid_plural); + return _gettext(\&ngettext, [ $msgid, $msgid_plural, $count ]); } sub __nx { my ($msgid, $msgid_plural, $count, %vars) = @_; + $msgid = Encode::encode_utf8($msgid); + $msgid_plural = Encode::encode_utf8($msgid_plural); + return _gettext(\&ngettext, [ $msgid, $msgid_plural, $count ], %vars); } @@ -114,24 +123,38 @@ sub __xn { sub __p { my ($msgctxt, $msgid) = @_; + $msgctxt = Encode::encode_utf8($msgctxt); + $msgid = Encode::encode_utf8($msgid); + return _gettext(\&pgettext, [ $msgctxt, $msgid ]); } sub __px { my ($msgctxt, $msgid, %vars) = @_; + $msgctxt = Encode::encode_utf8($msgctxt); + $msgid = Encode::encode_utf8($msgid); + return _gettext(\&pgettext, [ $msgctxt, $msgid ], %vars); } sub __np { my ($msgctxt, $msgid, $msgid_plural, $count) = @_; + $msgctxt = Encode::encode_utf8($msgctxt); + $msgid = Encode::encode_utf8($msgid); + $msgid_plural = Encode::encode_utf8($msgid_plural); + return _gettext(\&npgettext, [ $msgctxt, $msgid, $msgid_plural, $count ]); } sub __npx { my ($msgctxt, $msgid, $msgid_plural, $count, %vars) = @_; + $msgctxt = Encode::encode_utf8($msgctxt); + $msgid = Encode::encode_utf8($msgid); + $msgid_plural = Encode::encode_utf8($msgid_plural); + return _gettext(\&npgettext, [ $msgctxt, $msgid, $msgid_plural, $count], %vars); } -- 2.17.1