Bugzilla – Attachment 73910 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: Fix several issues in translation process
Bug-15395-Fix-several-issues-in-translation-proces.patch (text/plain), 7.60 KB, created by
Julian Maurice
on 2018-04-10 06:27:22 UTC
(
hide
)
Description:
Bug 15395: Fix several issues in translation process
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2018-04-10 06:27:22 UTC
Size:
7.60 KB
patch
obsolete
>From 784fa0c967cf90b1f4ae8b0683bf0d1c80b64ede Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 26 Apr 2017 11:03:40 +0200 >Subject: [PATCH] Bug 15395: Fix several issues in translation process > >- Change location of generated PO files to ease its integration into Pootle > (po/xx-XX-messages.po instead of xx_XX/LC_MESSAGES/Koha.po) >- Use msginit for PO creation to try to set correctly Plural-Forms header. If it > fails, set a default one >- 'install' command now creates the PO file if it doesn't already exist >- Fix locale name when language code is different from ll-CC (where ll is the > language code and CC is the country code). > >Test plan: >1. `perl translate install ar-Arab` should results in > po/ar/LC_MESSAGES/Koha.mo and po/ar-Arab-messages.po >2. `perl translate install gl` should results in > po/gl/LC_MESSAGES/Koha.mo and po/gl-messages.po >3. `perl translate install zh-Hans-CN` should results in > po/zh_CN/LC_MESSAGES/Koha.mo and po/zh-Hans-CN-messages.po >4. `perl translate install fr-FR` should results in > po/fr_FR/LC_MESSAGES/Koha.mo and po/fr-FR-messages.po >--- > misc/translator/LangInstaller.pm | 101 +++++++++++++++++++++------------------ > 1 file changed, 54 insertions(+), 47 deletions(-) > >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index ba2c8ae9f3..2acad828ea 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -78,6 +78,7 @@ sub new { > $self->{msgmerge} = `which msgmerge`; > $self->{msgfmt} = `which msgfmt`; > $self->{msgcat} = `which msgcat`; >+ $self->{msginit} = `which msginit`; > $self->{xgettext} = `which xgettext`; > $self->{sed} = `which sed`; > $self->{po2json} = "$Bin/po2json"; >@@ -85,6 +86,7 @@ sub new { > chomp $self->{msgmerge}; > chomp $self->{msgfmt}; > chomp $self->{msgcat}; >+ chomp $self->{msginit}; > chomp $self->{xgettext}; > chomp $self->{sed}; > >@@ -480,40 +482,54 @@ sub create_tmpl { > } > } > >-sub create_messages { >+sub locale_name { > my $self = shift; > >- my ($language, $country) = split /-/, $self->{lang}; >+ my ($language, $region, $country) = split /-/, $self->{lang}; >+ $country //= $region; > my $locale = $language; >- if ($country) { >+ if ($country && length($country) == 2) { > $locale .= '_' . $country; > } >- my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; > >- make_path($podir); >- say "Create messages ($locale)" if $self->{verbose}; >- system >- "$self->{cp} $self->{domain}.pot " . >- "$podir/$self->{domain}.po"; >+ return $locale; >+} >+ >+sub create_messages { >+ my $self = shift; >+ >+ my $pot = "$self->{domain}.pot"; >+ my $po = "$self->{path_po}/$self->{lang}-messages.po"; >+ >+ unless ( -f $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"; >+ >+ # 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)/'"; > } > > sub update_messages { > my $self = shift; > >- my ($language, $country) = split /-/, $self->{lang}; >- my $locale = $language; >- if ($country) { >- $locale .= '_' . $country; >+ my $pot = "$self->{domain}.pot"; >+ my $po = "$self->{path_po}/$self->{lang}-messages.po"; >+ >+ unless ( -f $pot ) { >+ $self->extract_messages(); > } >- my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; >- my $pofile = "$podir/$self->{domain}.po"; > >- say "Update messages ($locale)" if $self->{verbose}; >- if ( not -f $pofile ) { >- say "File $pofile does not exist" if $self->{verbose}; >+ if ( -f $po ) { >+ say "Update messages ($self->{lang})" if $self->{verbose}; >+ system "$self->{msgmerge} -U $po $pot"; >+ } else { > $self->create_messages(); > } >- system "$self->{msgmerge} -U $pofile $self->{domain}.pot"; > } > > sub extract_messages_from_templates { >@@ -524,6 +540,7 @@ sub extract_messages_from_templates { > my $parser = Template::Parser->new(); > > foreach my $file (@files) { >+ say "Extract messages from $file" if $self->{verbose}; > my $template = read_file("$intranetdir/$file"); > my $data = $parser->parse($template); > my $document = PPI::Document->new(\$data->{BLOCK}); >@@ -581,6 +598,8 @@ sub extract_messages_from_templates { > sub extract_messages { > my $self = shift; > >+ say "Extract messages into POT file" if $self->{verbose}; >+ > my $intranetdir = $self->{context}->config('intranetdir'); > my @files_to_scan; > my @directories_to_scan = ('.'); >@@ -654,37 +673,27 @@ sub extract_messages { > die "system call failed: $msgcat_cmd"; > } > >- if ( -f "$Bin/$self->{domain}.pot" ) { >- my $replace_charset_cmd = "$self->{sed} --in-place " . >- "$Bin/$self->{domain}.pot " . >- "--expression='s/charset=CHARSET/charset=UTF-8/'"; >- if (system($replace_charset_cmd) != 0) { >- die "system call failed: $replace_charset_cmd"; >- } >- } else { >- say "No messages found" if $self->{verbose}; >- return; >+ my $replace_charset_cmd = "$self->{sed} --in-place " . >+ "$Bin/$self->{domain}.pot " . >+ "--expression='s/charset=CHARSET/charset=UTF-8/'"; >+ if (system($replace_charset_cmd) != 0) { >+ die "system call failed: $replace_charset_cmd"; > } >- return 1; > } > > sub install_messages { > my ($self) = @_; > >- my ($language, $country) = split /-/, $self->{lang}; >- my $locale = $language; >- if ($country) { >- $locale .= '_' . $country; >- } >- my $podir = "$self->{path_po}/$locale/LC_MESSAGES"; >- my $pofile = "$podir/$self->{domain}.po"; >- my $mofile = "$podir/$self->{domain}.mo"; >+ my $locale = $self->locale_name(); >+ my $modir = "$self->{path_po}/$locale/LC_MESSAGES"; >+ my $pofile = "$self->{path_po}/$self->{lang}-messages.po"; >+ my $mofile = "$modir/$self->{domain}.mo"; > >- say "Install messages ($locale)" if $self->{verbose}; > if ( not -f $pofile ) { >- say "File $pofile does not exist" if $self->{verbose}; > $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` . '};'; >@@ -717,6 +726,7 @@ sub install { > $self->install_tmpl($files) unless $self->{pref_only}; > $self->install_prefs(); > $self->install_messages(); >+ $self->remove_pot(); > } > > >@@ -732,14 +742,13 @@ sub get_all_langs { > sub update { > my ($self, $files) = @_; > my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs(); >- my $extract_ok = $self->extract_messages(); > for my $lang ( @langs ) { > $self->set_lang( $lang ); > $self->update_tmpl($files) unless $self->{pref_only}; > $self->update_prefs(); >- $self->update_messages() if $extract_ok; >+ $self->update_messages(); > } >- $self->remove_pot() if $extract_ok; >+ $self->remove_pot(); > } > > >@@ -748,10 +757,8 @@ sub create { > return unless $self->{lang}; > $self->create_tmpl($files) unless $self->{pref_only}; > $self->create_prefs(); >- if ($self->extract_messages()) { >- $self->create_messages(); >- $self->remove_pot(); >- } >+ $self->create_messages(); >+ $self->remove_pot(); > } > > >-- >2.14.2
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