aboutsummaryrefslogtreecommitdiffstats
path: root/tools/replace_language_values.pl
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2010-09-28 00:18:39 +0000
committerplegall <plg@piwigo.org>2010-09-28 00:18:39 +0000
commit601f855ef5525111188518d189b95ce75a6056bc (patch)
treeda8cb2f6628876b1c38d24a42944688d6f4021fb /tools/replace_language_values.pl
parentc6a5f13d2307757a0328f9c8fac340938a17f90d (diff)
feature 1616: add a tool to replace language keys from a mapping file + replace values from a template file
git-svn-id: http://piwigo.org/svn/trunk@7026 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--tools/replace_language_values.pl61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/replace_language_values.pl b/tools/replace_language_values.pl
new file mode 100644
index 000000000..f901e1140
--- /dev/null
+++ b/tools/replace_language_values.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $replacement_file = $ARGV[0];
+my $language_dir = $ARGV[1];
+
+# load the new values for given keys
+my %new_value_of = ();
+open(my $ifh_rep, '<'.$replacement_file);
+while (<$ifh_rep>) {
+ if (m/^\$lang\['(.*)'\] \s* = \s* (.*);/x) {
+ $new_value_of{$1} = $2;
+ }
+}
+# use Data::Dumper; print Dumper(\%new_value_of); exit();
+
+my %replacement_performed_for = ();
+
+foreach my $file_code (qw/upgrade install admin common plugin/) {
+ my $filename = $language_dir.'/'.$file_code.'.lang.php';
+ # print $filename;
+ if (not -f $filename) {
+ # print ' is missing', "\n";
+ next;
+ }
+ print $filename.' is under process', "\n";
+
+ my $file_content = '';
+
+ open(my $ifh, '<'.$filename);
+ while (my $line = <$ifh>) {
+ if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) {
+ if (defined $new_value_of{$1}) {
+ $file_content.= '$lang[\''.$1.'\'] = '.$new_value_of{$1}.';'."\n";
+ $replacement_performed_for{$1}++;
+ }
+ else {
+ $file_content.= $line;
+ }
+ }
+ elsif ($line =~ m/^?>/) {
+ $file_content.= $line;
+ }
+ else {
+ $file_content.= $line;
+ }
+ }
+ close($ifh);
+
+ open(my $ofh, '>'.$filename);
+ print {$ofh} $file_content;
+ close($ofh);
+}
+
+foreach my $new_value (keys %new_value_of) {
+ if (not defined $replacement_performed_for{$new_value}) {
+ print 'no replacement performed on: ', $new_value, "\n";
+ }
+}