Bugzilla – Attachment 9415 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]
First draft for Koha localization using Locale::Maketext
0001-Bug-8044-First-draft-for-Koha-localization-using-Loc.patch (text/plain), 5.24 KB, created by
Julian Maurice
on 2012-05-04 13:05:04 UTC
(
hide
)
Description:
First draft for Koha localization using Locale::Maketext
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2012-05-04 13:05:04 UTC
Size:
5.24 KB
patch
obsolete
>From eacfda214810727223f2e89cb5382c4d91ad79b0 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 1/2] Bug 8044: First draft for Koha localization using > Locale::Maketext > >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 locale/LANG/messages.po. >To create PO file for a language, just make a directory under locale/ >and launch locale/update_po.pl. >The directory name must be in lowercase with '_' instead of '-'. >For example: for french, create locale/fr_fr/ directory. >Missing PO files are created, and existing ones are updated. >You can then translate the PO with your favorite editor. Strings will be >localized at runtime. >--- > Koha/I18N.pm | 29 +++++++++++++++++++++++ > locale/en/messages.po | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ > locale/update_po.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 152 insertions(+) > create mode 100644 Koha/I18N.pm > create mode 100644 locale/en/messages.po > create mode 100755 locale/update_po.pl > >diff --git a/Koha/I18N.pm b/Koha/I18N.pm >new file mode 100644 >index 0000000..a81a392 >--- /dev/null >+++ b/Koha/I18N.pm >@@ -0,0 +1,29 @@ >+package Koha::I18N; >+ >+use base qw(Locale::Maketext); >+ >+use C4::Templates; >+use C4::Context; >+ >+use Locale::Maketext::Lexicon { >+ '*' => [Gettext => C4::Context->config('intranetdir') . '/locale/*/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/locale/en/messages.po b/locale/en/messages.po >new file mode 100644 >index 0000000..4423ae4 >--- /dev/null >+++ b/locale/en/messages.po >@@ -0,0 +1,62 @@ >+# SOME DESCRIPTIVE TITLE. >+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER >+# This file is distributed under the same license as the PACKAGE package. >+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. >+# >+#, fuzzy >+msgid "" >+msgstr "" >+"Project-Id-Version: Koha\n" >+"Report-Msgid-Bugs-To: \n" >+"POT-Creation-Date: 2012-05-04 14:23+0200\n" >+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" >+"Last-Translator: \n" >+"Language-Team: English <koha-translate@lists.koha-community.org>\n" >+"Language: en\n" >+"MIME-Version: 1.0\n" >+"Content-Type: text/plain; charset=UTF-8\n" >+"Content-Transfer-Encoding: 8bit\n" >+ >+#: C4/Acquisition.pm:241 >+msgid "Contract name" >+msgstr "" >+ >+#: C4/Acquisition.pm:242 >+msgid "Order number" >+msgstr "" >+ >+#: C4/Acquisition.pm:243 >+msgid "Entry date" >+msgstr "" >+ >+#: C4/Acquisition.pm:244 >+msgid "ISBN" >+msgstr "" >+ >+#: C4/Acquisition.pm:245 >+msgid "Author" >+msgstr "" >+ >+#: C4/Acquisition.pm:246 >+msgid "Title" >+msgstr "" >+ >+#: C4/Acquisition.pm:247 >+msgid "Publisher code" >+msgstr "" >+ >+#: C4/Acquisition.pm:248 >+msgid "Collection title" >+msgstr "" >+ >+#: C4/Acquisition.pm:249 >+msgid "Notes" >+msgstr "" >+ >+#: C4/Acquisition.pm:250 >+msgid "Quantity" >+msgstr "" >+ >+#: C4/Acquisition.pm:251 >+msgid "RRP" >+msgstr "" >diff --git a/locale/update_po.pl b/locale/update_po.pl >new file mode 100755 >index 0000000..4987c6d >--- /dev/null >+++ b/locale/update_po.pl >@@ -0,0 +1,61 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use Data::Dumper; >+use FindBin qw($Bin); >+ >+my $localedir = $Bin; >+my $installdir = "$localedir/.."; >+ >+# Directories are not scanned recursively >+my @directories_to_scan = qw( >+ . C4 acqui admin authorities basket catalogue cataloguing circ errors >+ Koha labels members misc offline_circ opac patroncards reports >+ reserve reviews rotating_collections serials services sms suggestion tags >+ tools virtualshelves >+); >+ >+# Build files list >+my @files_to_scan; >+foreach my $dir (@directories_to_scan) { >+ opendir DIR, "$installdir/$dir" or die "Unable to open $dir: $!"; >+ while (readdir DIR) { >+ next unless ( -f "$installdir/$dir/$_" ); >+ next unless ( $_ =~ /(\.pl|\.pm)$/ ); >+ push @files_to_scan, "$dir/$_"; >+ } >+ closedir DIR; >+} >+ >+# Build languages list >+my @langs; >+opendir DIR, $localedir; >+while (readdir DIR) { >+ next unless ( -d "$localedir/$_" ); >+ next if ($_ eq '.' or $_ eq '..'); >+ push @langs, $_; >+} >+close DIR; >+ >+my $xgettext = `which xgettext`; >+chomp $xgettext; >+my $xgettext_cmd = "$xgettext -L Perl --from-code=UTF-8 -kmaketext -o messages.pot"; >+$xgettext_cmd .= " -D $installdir/$_" foreach (@directories_to_scan); >+$xgettext_cmd .= " $_" foreach (@files_to_scan); >+ >+say "Extracting strings from source..."; >+if (system($xgettext_cmd) != 0) { >+ die "system call failed : $xgettext_cmd"; >+} >+ >+foreach my $lang (@langs) { >+ if ( -f "$localedir/$lang/messages.po" ) { >+ say "Updating $lang..."; >+ system("msgmerge -U $localedir/$lang/messages.po messages.pot"); >+ } else { >+ say "No PO file for $lang. Creating one..."; >+ system("cp messages.pot $localedir/$lang/messages.po"); >+ } >+} >+ >+unlink "messages.pot"; >-- >1.7.10 >
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