From 7439bfd05c02d0f5cd04893daface1408c17904b Mon Sep 17 00:00:00 2001 From: plegall Date: Sat, 3 Apr 2010 21:16:34 +0000 Subject: Here comes a beta script to convert language keys in a set of 2.0 *.tpl files. Backup your *.tpl directory first. git-svn-id: http://piwigo.org/svn/trunk@5612 68402e56-0260-453c-a942-63ccdbb3a9ee --- tools/convert_template_to_2.1.pl | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/convert_template_to_2.1.pl diff --git a/tools/convert_template_to_2.1.pl b/tools/convert_template_to_2.1.pl new file mode 100644 index 000000000..a838e8f8b --- /dev/null +++ b/tools/convert_template_to_2.1.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# perl tools/convert_template_to_2.1.pl /path/to/tpl/files/directory + +use strict; +use warnings; + +use File::Find; + +my $base_dir = $ARGV[0]; + +# load the replacements +my @file_codes = qw/upgrade install admin common/; +my %replace_by = (); +foreach my $file_code (@file_codes) { + open(my $ifh_rep, ') { + if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) { + if ($1 ne $3 and length($1) > 0) { + $replace_by{$1} = $3; + } + } + } +} +# use Data::Dumper; print Dumper(\%replace_by); exit(); + +find(\&replace_keys, $base_dir); + +sub replace_keys { + if ($File::Find::name !~ m/tpl$/) { + return 0; + } + + my $file_content = ''; + open(my $fhi, '<', $File::Find::name); + while (<$fhi>) { + foreach my $from (keys %replace_by) { + my $to = $replace_by{$from}; + s/{'$from'\|\@translate/{'$to'|\@translate/g; + } + $file_content.= $_; + } + close($fhi); + + open(my $fho, '>', $File::Find::name); + print {$fho} $file_content; + close($fho); +} -- cgit v1.2.3