File Coverage

blib/lib/Win32/TRADOS/Languages.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Win32::TRADOS::Languages;
2            
3 1     1   32004 use strict;
  1         2  
  1         34  
4 1     1   6 use warnings;
  1         9  
  1         25  
5            
6 1     1   400 use Win32::RunAsAdmin;
  0            
  0            
7             use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
8             use Locale::Language;
9             use Carp;
10            
11             =head1 NAME
12            
13             Win32::TRADOS::Languages - Simplifies working with TRADOS Registry values
14            
15             =head1 VERSION
16            
17             Version 0.01
18            
19             =cut
20            
21             our $VERSION = '0.01';
22             our %languages = (
23             '00' => 'DV',
24             '01' => 'CY',
25             '02' => 'Syriac',
26             '03' => 'Northern Sotho',
27             '04' => '--',
28             '05' => '--',
29             '06' => '--',
30             '07' => 'NE',
31             '08' => '--',
32             '09' => '--',
33             '0A' => '--',
34             '0B' => '--',
35             '0C' => 'QU',
36             '0D' => '--',
37             '0E' => '--',
38             '0F' => '--',
39             '10' => 'BN',
40             '11' => 'PA',
41             '12' => 'GU',
42             '13' => 'OR',
43             '14' => 'ST', # Southern Sotho
44             '15' => 'SE',
45             '16' => 'KA',
46             '17' => 'HI',
47             '18' => 'AS',
48             '19' => 'MR',
49             '1A' => 'SA',
50             '1B' => 'Konkani',
51             '1C' => 'TA',
52             '1D' => 'TE',
53             '1E' => 'KN',
54             '1F' => 'ML',
55             '40' => 'NB',
56             '41' => 'PL',
57             '42' => 'PT',
58             '43' => 'RM',
59             '44' => 'IT',
60             '45' => 'JA',
61             '46' => 'KO',
62             '47' => 'NL',
63             '48' => 'SQ',
64             '49' => 'SV',
65             '4A' => 'TH',
66             '4B' => 'TR',
67             '4C' => 'RO',
68             '4D' => 'RU',
69             '4E' => 'HR', # Also Serbian and Bosnian.
70             '4F' => 'SK',
71             '50' => 'ZH',
72             '51' => 'CS',
73             '52' => 'DA',
74             '53' => 'DE',
75             '54' => '--',
76             '55' => 'AR',
77             '56' => 'BG',
78             '57' => 'CA',
79             '58' => 'FR',
80             '59' => 'HE',
81             '5A' => 'HU',
82             '5B' => 'IS',
83             '5C' => 'EL',
84             '5D' => 'EN',
85             '5E' => 'ES',
86             '5F' => 'FI',
87             '60' => 'FO',
88             '61' => 'MT',
89             '62' => 'GA',
90             '63' => 'MS',
91             '64' => '--',
92             '65' => 'XH',
93             '66' => 'ZU',
94             '67' => 'AF',
95             '68' => 'UZ',
96             '69' => 'TT',
97             '6A' => 'MN',
98             '6B' => 'GL',
99             '6C' => 'KK',
100             '6D' => 'SW',
101             '6E' => 'TL',
102             '6F' => 'KY',
103             '70' => 'SL',
104             '71' => 'ET',
105             '72' => 'LV',
106             '73' => 'LT',
107             '74' => 'UR',
108             '75' => 'ID',
109             '76' => 'UK',
110             '77' => 'BE',
111             '78' => 'AZ',
112             '79' => 'EU',
113             '7A' => 'Sorbian',
114             '7B' => 'MK',
115             '7C' => 'MI',
116             '7D' => 'FA',
117             '7E' => 'VI',
118             '7F' => 'HY',
119             );
120            
121            
122             =head1 SYNOPSIS
123            
124             TRADOS 2007 is a fantastically useful tool for the professional translator that is used on Windows.
125             Somewhere back in its history, it was decided to permit the Freelancer version of the tool to install
126             only five languages at once, and that has remained a technical limitation of the tool - the official
127             recommendation of SDL (the current owners of the software) is to de-install and re-install the entire
128             package if the five installed languages need to be changed. (To be fair, I wouldn't want to provide
129             the technical support for any other method, either.)
130            
131             However, they are all encoded in a single Registry key; this module contains a table of values for
132             the numeric codes used in that key with their ISO codes, and also some simple tools for reading and
133             writing the key. This saves a lot of time in de-installing and re-installing the package for those
134             of us who work with more than five languages.
135            
136             A command-line script ttx-lang is also included that exposes the functionality to the command line
137             in a convenient manner.
138            
139             =head1 METHODS
140            
141             =head2 get_idng
142            
143             Reads the value of the Registry key in question. Doesn't require elevated privileges, as it
144             obtains only read access to the Registry to do this. Croaks if it can't find the key.
145            
146             =cut
147            
148             sub get_idng {
149             my $key_not_found = 0;
150             my $LMkey = Win32::TieRegistry->Open ('HKEY_LOCAL_MACHINE', {Access=>Win32::TieRegistry::KEY_READ()});
151             $LMkey->Delimiter('/');
152             my $LMachine = {};
153             $LMkey->Tie($LMachine);
154            
155             my $key = $LMachine->{'SOFTWARE/Wow6432Node/TRADOS'} or $key_not_found = 1;
156             if ($key_not_found) {
157             $key_not_found = 0;
158             $key = $LMachine->{'/SOFTWARE/TRADOS'} or $key_not_found = 1;
159             }
160             if ($key_not_found) {
161             croak "TRADOS 2007 does not appear to be installed on your machine (can't find Registry key)";
162             }
163            
164             $key->{'Shared/IDNG//'} or croak "TRADOS 2007 appears to be installed, but your Registry is configured in an unexpected way.";
165             }
166            
167             =head2 set_idng ($idng)
168            
169             Sets the IDNG key to the value supplied. Requires elevated privileges. Croaks if it doesn't have them.
170            
171             =cut
172            
173             sub set_idng {
174             my $idng = shift;
175             my $LMkey = Win32::TieRegistry->Open ('HKEY_LOCAL_MACHINE', {Access=>Win32::TieRegistry::KEY_READ()|Win32::TieRegistry::KEY_WRITE()})
176             or croak "Not running with elevated privileges";
177             $LMkey->Delimiter('/');
178             my $LMachine = {};
179             $LMkey->Tie($LMachine);
180            
181             my $key_not_found = 0;
182             my $key = $LMachine->{'SOFTWARE/Wow6432Node/TRADOS'} or $key_not_found = 1;
183             if ($key_not_found) {
184             $key_not_found = 0;
185             $key = $LMachine->{'/SOFTWARE/TRADOS'} or $key_not_found = 1;
186             }
187            
188             $key->{'Shared/IDNG//'} = $idng;
189             }
190            
191             =head2 get_languages ($idng)
192            
193             Given an IDNG value, extracts the numeric language codes from it. Returns a list of the languages encoded.
194             Croaks if the IDNG doesn't look like an IDNG key.
195            
196             =cut
197            
198             sub get_languages {
199             my $idng = shift;
200             if (not $idng =~ /{(.*-.*-.*-.*-00)(.*)}/) {
201             croak "Unexpected IDNG value $idng encountered";
202             }
203             my ($prefix, $meat) = ($1, $2);
204             unpack("(A2)*", $meat);
205             }
206            
207             =head2 set_languages ($idng, @values)
208            
209             Given an IDNG value and one to five language codes, builds and returns a new IDNG key.
210             Croaks if the IDNG key given doesn't look like an IDNG key.
211            
212             =cut
213            
214             sub set_languages {
215             my $idng = shift;
216             if (not $idng =~ /{(.*-.*-.*-.*-00)(.*)}/) {
217             croak "Unexpected IDNG value $idng encountered";
218             }
219             my ($prefix, $meat) = ($1, $2);
220             sprintf ("{$prefix%s}", join ('', @_));
221             }
222            
223             =head2 idng2iso, idng2lang
224            
225             Given a TRADOS numeric language code, C looks up its ISO equivalent in the table of values.
226             C also calls C to convert that ISO code into the name of the language.
227             Has a little more logic to build values that are more appropriate to the TRADOS language list.
228            
229             =cut
230            
231             sub idng2iso {
232             my $language = shift;
233             $languages{$language} || "-- ($language)";
234             }
235            
236             sub idng2lang {
237             my $iso = idng2iso(shift);
238             my $ln = code2language($iso);
239             $ln = "Croatian/Serbian/Bosnian" if $iso eq 'HR';
240             $ln;
241             }
242            
243             =head2 iso2idng, lang2idng
244            
245             Given an ISO code, C looks for it in the table of numeric values. Returns C
246             if it can't find it there. C calls C first, and also includes some
247             other logic: returns '84' ("invalid language") for an undefined language or '--', passes
248             hex codes through unaffected, and converts ISO codes directly if they're passed.
249             This is your best bet to make sense of user input.
250            
251             =cut
252            
253             sub iso2idng {
254             my $language = lc(shift);
255             foreach my $n (keys %languages) {
256             if (lc($languages{$n}) eq $language) {
257             return $n;
258             }
259             }
260             return undef;
261             }
262            
263             sub lang2idng {
264             my $language = shift;
265             return '84' if not defined $language;
266             return '84' if $language eq '--';
267             if ($language =~ /^[0-9][0-9A-F]$/) {
268             $language =~ tr/a-z/A-Z/;
269             return $language;
270             }
271             my $ln = language2code ($language);
272             $language = $ln if $ln;
273             $language =~ tr/a-z/A-Z/;
274             $language = 'HR' if $language eq 'SR' or $language eq 'BS';
275             iso2idng ($language);
276             }
277            
278            
279             =head1 AUTHOR
280            
281             Michael Roberts, C<< >>
282            
283             =head1 BUGS
284            
285             Please report any bugs or feature requests to C, or through
286             the web interface at L. I will be notified, and then you'll
287             automatically be notified of progress on your bug as I make changes.
288            
289            
290            
291            
292             =head1 SUPPORT
293            
294             You can find documentation for this module with the perldoc command.
295            
296             perldoc Win32::TRADOS::Languages
297            
298            
299             You can also look for information at:
300            
301             =over 4
302            
303             =item * RT: CPAN's request tracker (report bugs here)
304            
305             L
306            
307             =item * AnnoCPAN: Annotated CPAN documentation
308            
309             L
310            
311             =item * CPAN Ratings
312            
313             L
314            
315             =item * Search CPAN
316            
317             L
318            
319             =back
320            
321            
322             =head1 ACKNOWLEDGEMENTS
323            
324            
325             =head1 LICENSE AND COPYRIGHT
326            
327             Copyright 2014 Michael Roberts.
328            
329             This program is free software; you can redistribute it and/or modify it
330             under the terms of the the Artistic License (2.0). You may obtain a
331             copy of the full license at:
332            
333             L
334            
335             Any use, modification, and distribution of the Standard or Modified
336             Versions is governed by this Artistic License. By using, modifying or
337             distributing the Package, you accept this license. Do not use, modify,
338             or distribute the Package, if you do not accept this license.
339            
340             If your Modified Version has been derived from a Modified Version made
341             by someone other than you, you are nevertheless required to ensure that
342             your Modified Version complies with the requirements of this license.
343            
344             This license does not grant you the right to use any trademark, service
345             mark, tradename, or logo of the Copyright Holder.
346            
347             This license includes the non-exclusive, worldwide, free-of-charge
348             patent license to make, have made, use, offer to sell, sell, import and
349             otherwise transfer the Package with respect to any patent claims
350             licensable by the Copyright Holder that are necessarily infringed by the
351             Package. If you institute patent litigation (including a cross-claim or
352             counterclaim) against any party alleging that the Package constitutes
353             direct or contributory patent infringement, then this Artistic License
354             to you shall terminate on the date that such litigation is filed.
355            
356             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
357             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
358             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
359             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
360             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
361             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
362             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
363             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
364            
365            
366             =cut
367            
368             1; # End of Win32::TRADOS::Languages