Bugzilla – Attachment 76328 Details for
Bug 15395
Internationalization: plural forms, context, and more
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15395: Keep JS translations separated from others
Bug-15395-Keep-JS-translations-separated-from-othe.patch (text/plain), 5.04 KB, created by
Julian Maurice
on 2018-06-25 06:33:05 UTC
(
hide
)
Description:
Bug 15395: Keep JS translations separated from others
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-06-25 06:33:05 UTC
Size:
5.04 KB
patch
obsolete
>From ff9854cb75ba46597da16d26f818078ff75923ed Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 22 Jun 2018 12:44:57 +0200 >Subject: [PATCH] Bug 15395: Keep JS translations separated from others > >It saves the browser from downloading a whole ~1Mib JSON file where 99% >of it will only be used on the server side. >The downside of this is that if the same strings appear in templates and >in JS files, they will have to be translated twice. >--- > misc/translator/LangInstaller.pm | 36 +++++++++++++++++--------------- > 1 file changed, 19 insertions(+), 17 deletions(-) > >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index 2acad828ea..141a410dd3 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -500,18 +500,22 @@ sub create_messages { > > my $pot = "$self->{domain}.pot"; > my $po = "$self->{path_po}/$self->{lang}-messages.po"; >+ my $js_pot = "$self->{domain}-js.pot"; >+ my $js_po = "$self->{path_po}/$self->{lang}-messages-js.po"; > >- unless ( -f $pot ) { >+ unless ( -f $pot && -f $js_pot ) { > $self->extract_messages(); > } > > say "Create messages ($self->{lang})" if $self->{verbose}; > my $locale = $self->locale_name(); > system "$self->{msginit} -i $pot -o $po -l $locale --no-translator"; >+ system "$self->{msginit} -i $js_pot -o $js_po -l $locale --no-translator"; > > # If msginit failed to correctly set Plural-Forms, set a default one >- system "$self->{sed} --in-place $po " >- . "--expression='s/Plural-Forms: nplurals=INTEGER; plural=EXPRESSION/Plural-Forms: nplurals=2; plural=(n != 1)/'"; >+ system "$self->{sed} --in-place " >+ . "--expression='s/Plural-Forms: nplurals=INTEGER; plural=EXPRESSION/Plural-Forms: nplurals=2; plural=(n != 1)/' " >+ . "$po $js_po"; > } > > sub update_messages { >@@ -519,14 +523,17 @@ sub update_messages { > > my $pot = "$self->{domain}.pot"; > my $po = "$self->{path_po}/$self->{lang}-messages.po"; >+ my $js_pot = "$self->{domain}-js.pot"; >+ my $js_po = "$self->{path_po}/$self->{lang}-messages-js.po"; > >- unless ( -f $pot ) { >+ unless ( -f $pot && -f $js_pot ) { > $self->extract_messages(); > } > >- if ( -f $po ) { >+ if ( -f $po && -f $js_po ) { > say "Update messages ($self->{lang})" if $self->{verbose}; > system "$self->{msgmerge} -U $po $pot"; >+ system "$self->{msgmerge} -U $js_po $js_pot"; > } else { > $self->create_messages(); > } >@@ -638,7 +645,7 @@ sub extract_messages { > . "-k__p:1c,2 -k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 " > . "-kN__ -kN__n:1,2 -kN__p:1c,2 -kN__np:1c,2,3"; > my $xgettext_cmd = "$self->{xgettext} -L Perl $xgettext_common_args " >- . "-o $Bin/$self->{domain}-perl.pot -D $tempdir -D $intranetdir"; >+ . "-o $Bin/$self->{domain}.pot -D $tempdir -D $intranetdir"; > $xgettext_cmd .= " $_" foreach (@files_to_scan); > > if (system($xgettext_cmd) != 0) { >@@ -647,7 +654,6 @@ sub extract_messages { > > my @js_dirs = ( > "$intranetdir/koha-tmpl/intranet-tmpl/prog/js", >- "$intranetdir/koha-tmpl/intranet-tmpl/prog/en/js", > "$intranetdir/koha-tmpl/opac-tmpl/bootstrap/js", > ); > >@@ -668,14 +674,9 @@ sub extract_messages { > die "system call failed: $xgettext_cmd"; > } > >- my $msgcat_cmd = "$self->{msgcat} --use-first -o $Bin/$self->{domain}.pot $Bin/$self->{domain}-perl.pot $Bin/$self->{domain}-js.pot"; >- if (system($msgcat_cmd) != 0) { >- die "system call failed: $msgcat_cmd"; >- } >- > my $replace_charset_cmd = "$self->{sed} --in-place " . >- "$Bin/$self->{domain}.pot " . >- "--expression='s/charset=CHARSET/charset=UTF-8/'"; >+ "--expression='s/charset=CHARSET/charset=UTF-8/' " . >+ "$Bin/$self->{domain}.pot $Bin/$self->{domain}-js.pot"; > if (system($replace_charset_cmd) != 0) { > die "system call failed: $replace_charset_cmd"; > } >@@ -688,16 +689,18 @@ sub install_messages { > my $modir = "$self->{path_po}/$locale/LC_MESSAGES"; > my $pofile = "$self->{path_po}/$self->{lang}-messages.po"; > my $mofile = "$modir/$self->{domain}.mo"; >+ my $js_pofile = "$self->{path_po}/$self->{lang}-messages-js.po"; > >- if ( not -f $pofile ) { >+ unless ( -f $pofile && -f $js_pofile ) { > $self->create_messages(); > } > say "Install messages ($locale)" if $self->{verbose}; > make_path($modir); > system "$self->{msgfmt} -o $mofile $pofile"; > >- my $js_locale_data = 'var json_locale_data = {"Koha":' . `$self->{po2json} $pofile` . '};'; >+ my $js_locale_data = 'var json_locale_data = {"Koha":' . `$self->{po2json} $js_pofile` . '};'; > my $progdir = $self->{context}->config('intrahtdocs') . '/prog'; >+ mkdir "$progdir/$self->{lang}/js"; > open my $fh, '>', "$progdir/$self->{lang}/js/locale_data.js"; > print $fh $js_locale_data; > close $fh; >@@ -716,7 +719,6 @@ sub remove_pot { > my $self = shift; > > unlink "$Bin/$self->{domain}.pot"; >- unlink "$Bin/$self->{domain}-perl.pot"; > unlink "$Bin/$self->{domain}-js.pot"; > } > >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15395
:
45797
|
45798
|
45799
|
46337
|
50023
|
50024
|
50025
|
50026
|
61873
|
61874
|
61875
|
61876
|
61934
|
61935
|
61977
|
62008
|
62041
|
62326
|
62327
|
62328
|
62329
|
62330
|
62331
|
62332
|
62333
|
62335
|
62709
|
65894
|
70974
|
70975
|
70976
|
71940
|
71941
|
71942
|
71943
|
71944
|
71945
|
71946
|
71947
|
71948
|
71949
|
71950
|
71951
|
71952
|
73901
|
73902
|
73903
|
73904
|
73905
|
73906
|
73907
|
73908
|
73909
|
73910
|
73911
|
73912
|
73913
|
76328
|
76329
|
76330
|
77475
|
77476
|
81152
|
81153
|
81154
|
81155
|
81156
|
81157
|
81158
|
81159
|
81167
|
81734
|
81735
|
81736
|
81737
|
81738
|
81739
|
81741
|
81742
|
81743