source: trunk/tools/convert_language_to_2.1.pl @ 15224

Last change on this file since 15224 was 5741, checked in by plg, 14 years ago

merge back r5740, I should have commited only the galleries directory

  • Property svn:eol-style set to LF
File size: 5.2 KB
Line 
1#!/usr/bin/perl
2
3# Here is the way I finally used this script:
4#
5# for language in ar_SA cz_CZ da_DK de_DE es_AR es_ES hr_HR hu_HU it_IT ja_JP nl_NL pl_PL pt_BR pt_PT ru_RU sr_RS vi_VN zh_CN
6# do
7#   export PWG_LANG=$language
8#   rm -rf language/$PWG_LANG
9#   cp -r ../branches/2.0/language/$PWG_LANG language/
10#   perl tools/convert_language_to_2.1.pl language/$PWG_LANG
11# done
12
13use strict;
14use warnings;
15
16my $language_dir = $ARGV[0];
17
18my @file_codes = qw/upgrade install admin common/;
19
20my %ignore_keys = (
21    'user_status_admin' => '',
22    'user_status_generic' => '',
23    'user_status_guest' => '',
24    'user_status_normal' => '',
25    'user_status_webmaster' => '',
26    'Level 0' => '',
27    'Level 1' => '',
28    'Level 2' => '',
29    'Level 4' => '',
30    'Level 8' => '',
31    'ACCESS_0' => '',
32    'ACCESS_1' => '',
33    'ACCESS_2' => '',
34    'ACCESS_3' => '',
35    'ACCESS_4' => '',
36    'ACCESS_5' => '',
37    'month' => '',
38    'day' => '',
39    'chronology_monthly_calendar' => '',
40    'chronology_monthly_list' => '',
41    'chronology_weekly_list' => '',
42);
43
44my %remove_keys = (
45    common => {
46        "You can\\'t upload pictures in this category" => '',
47        'display pictures added on' => '',
48        'Email address is missing' => '',
49        'Delete: %s' => '',
50        'All tags must match' => '',
51        'Validate: %s' => '',
52        'Upgrade from %s to %s' => '',
53    },
54    admin => {
55        'nbm_content_goto_2' => '',
56        'nbm_content_hello_2' => '',
57        'nbm_redirect_msg' => '',
58
59        'username' => '',
60        'No tag defined. Use Administration>Pictures>Tags' => '',
61        'Remote site url must start by http or https and must only contain characters among "/", "a-zA-Z0-9", "-" or "_"' => '',
62        'path' => '',
63        'Unable to retrieve server informations since allow_url_fopen is disabled.' => '',
64        'The following tag were deleted' => '',
65        'Remote site' => '',
66        'Piwigo home' => '',
67        'Move up' => '',
68        'Instructions' => '',
69        'Hits' => '',
70        'General' => '',
71        'Gallery description' => '',
72        'Extensions' => '',
73        'Demo' => '',
74        'Categories ascending alphanumerically ordered' => '',
75        'Categories descending alphanumerically ordered' => '',
76        'Categories sorted in ascending order ⇓' => '',
77        'Categories sorted in ascending order ⇓' => '',
78        'Categories sorted in descending order ⇑' => '',
79        'Categories sorted in descending order ⇑' => '',
80        'Bugs' => '',
81        'Automatic installation' => '',
82        'Upgrade from version %s to %s' => '',
83        'Upgrade from %s to %s' => '',
84        'Upload Form' => '',
85    },
86    upgrade => {
87        'Are you sure?' => '',
88        'In <i>%s</i>, before <b>?></b>, insert:' => '',
89    },
90    install => {
91        'Parameters are correct' => '',
92        'Installation finished' => '',
93        'The next step of the installation is now possible' => '',
94        'next step' => '',
95    }
96);
97
98my %to_copy = ();
99
100# load the replacements
101my %replace_by = ();
102foreach my $file_code (@file_codes) {
103    open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php');
104    while (<$ifh_rep>) {
105        if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) {
106            if ($1 ne $3 and length($1) > 0) {
107                $replace_by{$1} = $3;
108            }
109        }
110    }
111}
112# use Data::Dumper; print Dumper(\%replace_by); exit();
113
114my $append_to_common = '';
115
116foreach my $file_code (@file_codes) {
117    my $filename = $language_dir.'/'.$file_code.'.lang.php';
118    print $filename;
119    if (not -f $filename) {
120        print ' is missing', "\n";
121        next;
122    }
123    print ' is under process', "\n";
124
125    if ($file_code eq 'admin') {
126        %to_copy = (
127            'Are you sure?' => '',
128            'Email address is missing. Please specify an email address.' => '',
129            'delete this comment' => '',
130            'validate this comment' => '',
131        );
132    }
133    else {
134        %to_copy = ();
135    }
136
137    my $file_content = '';
138    my $copy_content = '';
139
140    open(my $ifh, '<'.$language_dir.'/'.$file_code.'.lang.php');
141    while (my $line = <$ifh>) {
142        if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) {
143            if (defined $remove_keys{$file_code}{$1}) {
144                next;
145            }
146            elsif (defined $ignore_keys{$1}) {
147                $file_content.= $line;
148            }
149            elsif (defined $to_copy{$1}) {
150                $append_to_common.= $line;
151            }
152            elsif (defined $replace_by{$1}) {
153                my $search = quotemeta($1);
154                my $replace = $replace_by{$1};
155
156                $line =~ s{$search}{$replace};
157
158                if (defined $to_copy{$replace}) {
159                    $append_to_common.= $line;
160                }
161                else {
162                    $file_content.= $line;
163                }
164            }
165            else {
166                $file_content.= $line;
167            }
168        }
169        elsif ($line =~ m/^?>/) {
170            if ('common' eq $file_code) {
171                $file_content.= $append_to_common;
172            }
173            $file_content.= $line;
174        }
175        else {
176            $file_content.= $line;
177        }
178    }
179    close($ifh);
180
181    open(my $ofh, '>'.$language_dir.'/'.$file_code.'.lang.php');
182    print {$ofh} $file_content;
183    close($ofh);
184}
Note: See TracBrowser for help on using the repository browser.