Debian Codegraph @

internal/translate

raw
1 #!/usr/bin/perl -w
2
3 # This will create the YAML portion of the translation file from
4 # two sources:
5 # the locale files
6 # a google translation
7 #
8 # To do this, first translate the file 'dm_translate.html' at
9 # http://translate.google.com/
10 # and paste the results into the file:
11 # /tmp/translate
12 #
13 # Next set the locale in the following line, and then run the
14 # program.
15
16 $locale = 'tr';
17
18 ##########################################################################
19
20 use DateTime::Locale;
21 use Encode;
22
23 my $obj = DateTime::Locale->load($locale);
24 my $tim = $obj->time_format_medium();
25
26 my @trans = `cat /tmp/translate`;
27 chomp(@trans);
28
29 while (! $trans[0]) {
30 shift(@trans);
31 }
32
33 ##########################################################################
34
35 my($hm,$ms);
36 if ($tim =~ /hh(.)mm/i) {
37 $hm = '"[' . $1 . ']"';
38 }
39 if ($tim =~ /mm(.)ss/i) {
40 $ms = '"[' . $1 . ']"';
41 }
42 print_list(1,"ampm", $obj->am_pm_abbreviated());
43
44 ###
45
46 @list = translate(\@trans);
47 print_list(0,"at",\@list);
48
49 ###
50
51 print_list(1,"day_abb", $obj->day_format_abbreviated(), $obj->day_stand_alone_abbreviated());
52 print_list(1,"day_char", $obj->day_format_narrow(), $obj->day_stand_alone_narrow());
53 print_list(1,"day_name", $obj->day_format_wide(), $obj->day_stand_alone_wide());
54
55 ###
56
57 @list = translate(\@trans);
58 print_list(0,"each",\@list);
59
60 @list = translate(\@trans);
61 print_list(0,"fields",\@list);
62
63 @list = translate(\@trans);
64 print_list(0,"last",\@list);
65
66 @list = translate(\@trans);
67 print_list(0,"mode",\@list);
68
69 ###
70
71 print_list(1,"month_abb", $obj->month_format_abbreviated(), $obj->month_stand_alone_abbreviated());
72 print_list(1,"month_name",$obj->month_format_wide(), $obj->month_stand_alone_wide());
73
74 ###
75
76 @list = translate(\@trans);
77 print_list(0,"nextprev",\@list);
78
79 ###
80
81 @list = translate(\@trans);
82 print "nth:\n";
83 foreach my $line (@list) {
84 $line =~ s/^ \S+ ,\s* \S+ ,\s* \S+ \s+//x;
85 if ($line =~ / (.*?) ,\s* (.*?) ,\s* (.*) $/x) {
86 ($nth,$num,$numth) = ($1,$2,$3);
87 print " -\n";
88 print " - $nth\n";
89 print " - ''\n";
90 print " - $num\n";
91 print " - $numth\n" if ($num ne $numth);
92 } else {
93 print " -\n";
94 print " - $line\n";
95 }
96 }
97
98 ###
99
100 @list = translate(\@trans);
101 print_list(0,"of",\@list);
102
103 @list = translate(\@trans);
104 print_list(0,"offset_date",\@list);
105
106 @list = translate(\@trans);
107 print_list(0,"offset_time",\@list);
108
109 @list = translate(\@trans);
110 print_list(0,"on",\@list);
111
112 ###
113
114 print_val ("sephm",$hm);
115 print_val ("sepms",$ms);
116
117 ###
118
119 @list = translate(\@trans);
120 print_list(0,"times",\@list);
121
122 @list = translate(\@trans);
123 print_list(0,"when",\@list);
124
125 ##########################################################################
126
127 sub translate {
128 my($trans) = @_;
129
130 while (! $$trans[0]) {
131 shift(@$trans);
132 }
133
134 my @ret;
135 while ($$trans[0]) {
136 push(@ret,shift(@$trans));
137 }
138
139 return @ret;
140 }
141
142 sub print_val {
143 my($label,$val) = @_;
144 return if (! $val);
145
146 print "$label:\n";
147 print " - $val\n";
148 }
149
150 sub print_list {
151 my($utf,$label,$vals,$vals2) = @_;
152 my @vals;
153 if (ref($vals)) {
154 @vals = @$vals
155 } elsif ($vals) {
156 @vals = ($vals);
157 }
158
159 my @vals2;
160 if (ref($vals2)) {
161 @vals2 = @$vals2;
162 } elsif ($vals2) {
163 @vals2 = ($vals2);
164 }
165
166 print "$label:\n";
167
168 if (@vals) {
169 foreach my $val (@vals) {
170 $val = encode_utf8(lc($val)) if ($utf);
171 print " -\n";
172
173 if ($utf) {
174 my $ascii = decode_utf8($val);
175 $ascii = encode("ascii",$ascii);
176 if ($ascii ne $val) {
177 print " - $ascii\n";
178 }
179 }
180
181 print " - $val\n";
182 if (@vals2) {
183 $val2 = encode_utf8(lc(shift(@vals2)));
184 if ($val2 ne $val) {
185 print " - $val2\n";
186 }
187 }
188 }
189
190 } else {
191 print " TRANSLATE\n";
192 }
193 }
194
195 # Local Variables:
196 # mode: cperl
197 # indent-tabs-mode: nil
198 # cperl-indent-level: 3
199 # cperl-continued-statement-offset: 2
200 # cperl-continued-brace-offset: 0
201 # cperl-brace-offset: 0
202 # cperl-brace-imaginary-offset: 0
203 # cperl-label-offset: 0
204 # End: