Bugzilla – Attachment 11689 Details for
Bug 8044
Localization for Perl scripts and modules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED_OFF] First draft for Koha localization using Locale::Maketext
patch.txt (text/plain), 5.05 KB, created by
Marcel de Rooy
on 2012-08-20 08:08:18 UTC
(
hide
)
Description:
[SIGNED_OFF] First draft for Koha localization using Locale::Maketext
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2012-08-20 08:08:18 UTC
Size:
5.05 KB
patch
obsolete
>From 88ed1d4abdf438c8437c6a8d6abcda46e238a73f Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 4 May 2012 14:33:10 +0200 >Subject: [PATCH] Bug 8044: First draft for Koha localization using > Locale::Maketext >Content-Type: text/plain; charset="utf-8" > >You have to use the new module Koha::I18N > >Code example: > use Koha::I18N; > use CGI; > > my $input = new CGI; > my $lh = Koha::I18N->get_handle_from_context($input, 'intranet'); > > print $lh->maketext("Localized string!"); > >PO files are in misc/translator/po/LANG-messages.po. >Creation of PO files are integrated to existing workflow, so to create >PO file for a language, just run in misc/translator: > ./translate create LANG >To update: > ./translate update LANG >You can then translate the PO with your favorite editor. Strings will be >localized at runtime. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Works as advertised. Some details needing further attention noted on bug report. >--- > Koha/I18N.pm | 34 +++++++++++++++++++ > misc/translator/LangInstaller.pm | 66 ++++++++++++++++++++++++++++++++++++++ > 2 files changed, 100 insertions(+), 0 deletions(-) > create mode 100644 Koha/I18N.pm > >diff --git a/Koha/I18N.pm b/Koha/I18N.pm >new file mode 100644 >index 0000000..dba57da >--- /dev/null >+++ b/Koha/I18N.pm >@@ -0,0 +1,34 @@ >+package Koha::I18N; >+ >+use base qw(Locale::Maketext); >+ >+use C4::Templates; >+use C4::Context; >+ >+use Locale::Maketext::Lexicon { >+ 'en' => ['Auto'], >+ '*' => [ >+ Gettext => >+ C4::Context->config('intranetdir') >+ . '/misc/translator/po/*-messages.po' >+ ], >+ '_AUTO' => 1, >+}; >+ >+sub get_handle_from_context { >+ my ($class, $cgi, $interface) = @_; >+ >+ my $lh; >+ my $lang = C4::Templates::getlanguage($cgi, $interface); >+ if ($lang) { >+ $lh = $class->get_handle($lang) >+ or die "No language handle for '$lang'"; >+ } else { >+ $lh = $class->get_handle() >+ or die "Can't get a language handle"; >+ } >+ >+ return $lh; >+} >+ >+1; >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index f9abda6..0cb8de2 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -53,6 +53,13 @@ sub new { > $self->{process} = "$Bin/tmpl_process3.pl " . ($verbose ? '' : '-q'); > $self->{path_po} = "$Bin/po"; > $self->{po} = {}; >+ $self->{domain} = 'messages'; >+ $self->{cp} = `which cp`; >+ $self->{msgmerge} = `which msgmerge`; >+ $self->{xgettext} = `which xgettext`; >+ chomp $self->{cp}; >+ chomp $self->{msgmerge}; >+ chomp $self->{xgettext}; > > # Get all .pref file names > opendir my $fh, $self->{path_pref_en}; >@@ -355,6 +362,59 @@ sub create_tmpl { > } > } > >+sub create_messages { >+ my $self = shift; >+ >+ system >+ "$self->{cp} $self->{domain}.pot " . >+ "$self->{path_po}/$self->{lang}-$self->{domain}.po"; >+} >+ >+sub update_messages { >+ my $self = shift; >+ >+ system >+ "$self->{msgmerge} -U " . >+ "$self->{path_po}/$self->{lang}-$self->{domain}.po " . >+ "$self->{domain}.pot"; >+} >+ >+sub extract_messages { >+ my $self = shift; >+ >+ my $intranetdir = $self->{context}->config('intranetdir'); >+ my @files_to_scan; >+ my @directories_to_scan = ('.'); >+ my @blacklist = qw(blib koha-tmpl skel tmp t); >+ while (@directories_to_scan) { >+ my $dir = shift @directories_to_scan; >+ opendir DIR, "$intranetdir/$dir" or die "Unable to open $dir: $!"; >+ foreach my $entry (readdir DIR) { >+ next if $entry =~ /^\./; >+ my $relentry = "$dir/$entry"; >+ $relentry =~ s|^\./||; >+ if (-d "$intranetdir/$relentry" and not grep /^$relentry$/, @blacklist) { >+ push @directories_to_scan, "$relentry"; >+ } elsif (-f "$intranetdir/$relentry" and $relentry =~ /(pl|pm)$/) { >+ push @files_to_scan, "$relentry"; >+ } >+ } >+ } >+ >+ my $xgettext_cmd = "$self->{xgettext} -L Perl --from-code=UTF-8 " . >+ "-kmaketext -o $Bin/$self->{domain}.pot -D $intranetdir"; >+ $xgettext_cmd .= " $_" foreach (@files_to_scan); >+ >+ if (system($xgettext_cmd) != 0) { >+ die "system call failed: $xgettext_cmd"; >+ } >+} >+ >+sub remove_pot { >+ my $self = shift; >+ >+ unlink "$Bin/$self->{domain}.pot"; >+} > > sub install { > my $self = shift; >@@ -376,11 +436,14 @@ sub get_all_langs { > sub update { > my $self = shift; > my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs(); >+ $self->extract_messages(); > for my $lang ( @langs ) { > $self->set_lang( $lang ); > $self->update_tmpl() unless $self->{pref_only}; > $self->update_prefs(); >+ $self->update_messages(); > } >+ $self->remove_pot(); > } > > >@@ -389,6 +452,9 @@ sub create { > return unless $self->{lang}; > $self->create_tmpl() unless $self->{pref_only}; > $self->create_prefs(); >+ $self->extract_messages(); >+ $self->create_messages(); >+ $self->remove_pot(); > } > > >-- >1.7.7.6 >
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 8044
:
9415
|
9416
|
9427
|
9449
|
9910
|
9911
|
11689
|
11690
|
11691
|
11693
|
11694
|
11695
|
11696
|
11697
|
13218
|
13219
|
13220
|
13221
|
17711
|
17712
|
17713
|
17714
|
19100
|
19101
|
19102
|
19103
|
20366
|
20367
|
20368
|
20369
|
20370
|
25964
|
25965
|
25966
|
25967