From: Frédéric Demians f.demi...@tamil.fr
Signed-off-by: Chris Cormack chr...@catalyst.net.nz
---
misc/translator/LangInstaller.pm | 432 ++
misc/translator/install-code.pl | 47
misc/translator/install.pl | 32 ---
misc/translator/pref-trans | 312 ---
misc/translator/rebuild_lang.sh |9 -
misc/translator/translate| 126 +++
6 files changed, 558 insertions(+), 400 deletions(-)
create mode 100755 misc/translator/LangInstaller.pm
delete mode 100755 misc/translator/install-code.pl
delete mode 100755 misc/translator/install.pl
delete mode 100755 misc/translator/pref-trans
delete mode 100755 misc/translator/rebuild_lang.sh
create mode 100755 misc/translator/translate
diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm
new file mode 100755
index 000..dbad9ea
--- /dev/null
+++ b/misc/translator/LangInstaller.pm
@@ -0,0 +1,432 @@
+package LangInstaller;
+
+use strict;
+use warnings;
+
+use C4::Context;
+use YAML::Syck qw( Dump LoadFile );
+use Locale::PO;
+
+
+sub set_lang {
+my ($self, $lang) = @_;
+
+$self-{lang} = $lang;
+$self-{po_path_lang} = $self-{context}-config('intrahtdocs') .
+/prog/$lang/modules/admin/preferences;
+}
+
+
+sub new {
+my ($class, $lang, $pref_only) = @_;
+
+my $self = { };
+
+my $context = C4::Context-new();
+$self-{context} = $context;
+$self-{path_pref_en}= $context-config('intrahtdocs') .
+ '/prog/en/modules/admin/preferences';
+set_lang( $self, $lang ) if $lang;
+$self-{pref_only} = $pref_only;
+$self-{translator_path} = $context-config('intranetdir') .
/misc/translator;
+$self-{path_po} = $self-{translator_path} . /po;
+$self-{po} = {};
+
+# Get all .pref file names
+opendir my $fh, $self-{path_pref_en};
+my @pref_files = grep { /.pref/ } readdir($fh);
+close $fh;
+$self-{pref_files} = \...@pref_files;
+
+# Get all available language codes
+opendir $fh, $self-{path_po};
+my @langs = map { ($_) =~ /(.*)-i-opac/ }
+grep { $_ =~ /.*-opac-/ } readdir($fh);
+closedir $fh;
+$self-{langs} = \...@langs;
+
+# Map for both interfaces opac/intranet
+$self-{interface} = {
+opac = {
+dir= $context-config('opachtdocs') . '/prog',
+suffix = '-i-opac-t-prog-v-3002000.po',
+},
+intranet = {
+dir= $context-config('intrahtdocs') . '/prog',
+suffix = '-i-staff-t-prog-v-3002000.po',
+}
+};
+
+bless $self, $class;
+}
+
+
+sub po_filename {
+my $self = shift;
+
+my $context= C4::Context-new;
+my $trans_path = $context-config('intranetdir') . '/misc/translator/po';
+my $trans_file = $trans_path/ . $self-{lang} . -pref.po;
+return $trans_file;
+}
+
+
+sub po_append {
+my ($self, $id, $comment) = @_;
+my $po = $self-{po};
+my $p = $po-{$id};
+if ( $p ) {
+$p-comment( $p-comment . \n . $comment );
+}
+else {
+$po-{$id} = Locale::PO-new(
+-comment = $comment,
+-msgid = $id,
+-msgstr = ''
+);
+}
+}
+
+
+sub add_prefs {
+my ($self, $comment, $prefs) = @_;
+
+for my $pref ( @$prefs ) {
+my $pref_name = '';
+for my $element ( @$pref ) {
+if ( ref( $element) eq 'HASH' ) {
+$pref_name = $element-{pref};
+last;
+}
+}
+for my $element ( @$pref ) {
+if ( ref( $element) eq 'HASH' ) {
+while ( my ($key, $value) = each(%$element) ) {
+next unless $key eq 'choices';
+next unless ref($value) eq 'HASH';
+for my $ckey ( keys %$value ) {
+my $id = $self-{file} . #$pref_name# .
$value-{$ckey};
+$self-po_append( $id, $comment );
+}
+}
+}
+elsif ( $element ) {
+$self-po_append( $self-{file} . #$pref_name# $element,
$comment );
+}
+}
+}
+}
+
+
+sub get_trans_text {
+my ($self, $id) = @_;
+
+my $po = $self-{po}-{$id};
+return unless $po;
+return Locale::PO-dequote($po-msgstr);
+}
+
+
+sub update_tab_prefs {
+my ($self, $pref, $prefs) = @_;
+
+for my $p ( @$prefs ) {
+my $pref_name = '';
+next unless $p;
+for my $element ( @$p ) {
+if ( ref( $element) eq 'HASH' ) {
+$pref_name = $element-{pref};
+last;
+}
+}
+for my $i ( 0...@$p-1 ) {
+my $element = $p-[$i];
+if ( ref( $element) eq 'HASH' ) {
+while ( my ($key, $value) = each(%$element) ) {
+