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

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

Fix missing keys: some keys have been removed by mistake during the massive
key conversion.

Remove some language keys that are really obsolete. I've updated the script
to convert language files to 2.1, I will apply "obsolete keys removal" process
in a 2nd step on other languages.

  • Property svn:eol-style set to LF
File size: 5.0 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    },
52    admin => {
53        'nbm_content_goto_2' => '',
54        'nbm_content_hello_2' => '',
55        'nbm_redirect_msg' => '',
56
57        'username' => '',
58        'No tag defined. Use Administration>Pictures>Tags' => '',
59        'Remote site url must start by http or https and must only contain characters among "/", "a-zA-Z0-9", "-" or "_"' => '',
60        'path' => '',
61        'Unable to retrieve server informations since allow_url_fopen is disabled.' => '',
62        'The following tag were deleted' => '',
63        'Remote site' => '',
64        'Piwigo home' => '',
65        'Move up' => '',
66        'Instructions' => '',
67        'Hits' => '',
68        'General' => '',
69        'Gallery description' => '',
70        'Extensions' => '',
71        'Demo' => '',
72        'Categories ascending alphanumerically ordered' => '',
73        'Categories descending alphanumerically ordered' => '',
74        'Categories sorted in ascending order ⇓' => '',
75        'Categories sorted in ascending order ⇓' => '',
76        'Categories sorted in descending order ⇑' => '',
77        'Categories sorted in descending order ⇑' => '',
78        'Bugs' => '',
79        'Automatic installation' => '',
80    },
81    upgrade => {
82        'Are you sure?' => '',
83        'In <i>%s</i>, before <b>?></b>, insert:' => '',
84    },
85    install => {
86        'Parameters are correct' => '',
87        'Installation finished' => '',
88    }
89);
90
91my %to_copy = ();
92
93# load the replacements
94my %replace_by = ();
95foreach my $file_code (@file_codes) {
96    open(my $ifh_rep, '<language/templates/'.$file_code.'.lang.php');
97    while (<$ifh_rep>) {
98        if (m/^\$lang\['(.*)'\] \s* = \s* (['"])(.*)\2;/x) {
99            if ($1 ne $3 and length($1) > 0) {
100                $replace_by{$1} = $3;
101            }
102        }
103    }
104}
105# use Data::Dumper; print Dumper(\%replace_by); exit();
106
107my $append_to_common = '';
108
109foreach my $file_code (@file_codes) {
110    my $filename = $language_dir.'/'.$file_code.'.lang.php';
111    print $filename;
112    if (not -f $filename) {
113        print ' is missing', "\n";
114        next;
115    }
116    print ' is under process', "\n";
117
118    if ($file_code eq 'admin') {
119        %to_copy = (
120            'Are you sure?' => '',
121            'Email address is missing. Please specify an email address.' => '',
122            'delete this comment' => '',
123            'validate this comment' => '',
124        );
125    }
126    else {
127        %to_copy = ();
128    }
129
130    my $file_content = '';
131    my $copy_content = '';
132
133    open(my $ifh, '<'.$language_dir.'/'.$file_code.'.lang.php');
134    while (my $line = <$ifh>) {
135        if ($line =~ m/^\$lang\['(.*)'\] \s* =/x) {
136            if (defined $remove_keys{$file_code}{$1}) {
137                next;
138            }
139            elsif (defined $ignore_keys{$1}) {
140                $file_content.= $line;
141            }
142            elsif (defined $to_copy{$1}) {
143                $append_to_common.= $line;
144            }
145            elsif (defined $replace_by{$1}) {
146                my $search = quotemeta($1);
147                my $replace = $replace_by{$1};
148
149                $line =~ s{$search}{$replace};
150
151                if (defined $to_copy{$replace}) {
152                    $append_to_common.= $line;
153                }
154                else {
155                    $file_content.= $line;
156                }
157            }
158            else {
159                $file_content.= $line;
160            }
161        }
162        elsif ($line =~ m/^?>/) {
163            if ('common' eq $file_code) {
164                $file_content.= $append_to_common;
165            }
166            $file_content.= $line;
167        }
168        else {
169            $file_content.= $line;
170        }
171    }
172    close($ifh);
173
174    open(my $ofh, '>'.$language_dir.'/'.$file_code.'.lang.php');
175    print {$ofh} $file_content;
176    close($ofh);
177}
Note: See TracBrowser for help on using the repository browser.