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

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

bug 1589: remove obsolete .csvignore file

  • Property svn:eol-style set to LF
File size: 5.3 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        'install_end_message' => '',
96    }
97);
98
99my %to_copy = ();
100
101# load the replacements
102my %replace_by = ();
103foreach my $file_code (@file_codes) {
104    open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php');
105    while (<$ifh_rep>) {
106        if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) {
107            if ($1 ne $3 and length($1) > 0) {
108                $replace_by{$1} = $3;
109            }
110        }
111    }
112}
113# use Data::Dumper; print Dumper(\%replace_by); exit();
114
115my $append_to_common = '';
116
117foreach my $file_code (@file_codes) {
118    my $filename = $language_dir.'/'.$file_code.'.lang.php';
119    print $filename;
120    if (not -f $filename) {
121        print ' is missing', "\n";
122        next;
123    }
124    print ' is under process', "\n";
125
126    if ($file_code eq 'admin') {
127        %to_copy = (
128            'Are you sure?' => '',
129            'Email address is missing. Please specify an email address.' => '',
130            'delete this comment' => '',
131            'validate this comment' => '',
132        );
133    }
134    else {
135        %to_copy = ();
136    }
137
138    my $file_content = '';
139    my $copy_content = '';
140
141    open(my $ifh, '<'.$language_dir.'/'.$file_code.'.lang.php');
142    while (my $line = <$ifh>) {
143        if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) {
144            if (defined $remove_keys{$file_code}{$1}) {
145                next;
146            }
147            elsif (defined $ignore_keys{$1}) {
148                $file_content.= $line;
149            }
150            elsif (defined $to_copy{$1}) {
151                $append_to_common.= $line;
152            }
153            elsif (defined $replace_by{$1}) {
154                my $search = quotemeta($1);
155                my $replace = $replace_by{$1};
156
157                $line =~ s{$search}{$replace};
158
159                if (defined $to_copy{$replace}) {
160                    $append_to_common.= $line;
161                }
162                else {
163                    $file_content.= $line;
164                }
165            }
166            else {
167                $file_content.= $line;
168            }
169        }
170        elsif ($line =~ m/^?>/) {
171            if ('common' eq $file_code) {
172                $file_content.= $append_to_common;
173            }
174            $file_content.= $line;
175        }
176        else {
177            $file_content.= $line;
178        }
179    }
180    close($ifh);
181
182    open(my $ofh, '>'.$language_dir.'/'.$file_code.'.lang.php');
183    print {$ofh} $file_content;
184    close($ofh);
185}
Note: See TracBrowser for help on using the repository browser.