Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tools/loadICU.tcl @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 18.8 KB
Line 
1#----------------------------------------------------------------------
2#
3# loadICU,tcl --
4#
5#       Extracts locale strings from a distribution of ICU
6#       (http://oss.software.ibm.com/developerworks/opensource/icu/project/)
7#       and makes Tcl message catalogs for the 'clock' command.
8#
9# Usage:
10#       loadICU.tcl sourceDir destDir
11#
12# Parameters:
13#       sourceDir -- Path name of the 'data' directory of your ICU4C
14#                    distribution.
15#       destDir -- Directory into which the Tcl message catalogs should go.
16#
17# Results:
18#       None.
19#
20# Side effects:
21#       Creates the message catalogs.
22#
23#----------------------------------------------------------------------
24#
25# Copyright (c) 2004 by Kevin B. Kenny.  All rights reserved.
26# See the file "license.terms" for information on usage and redistribution
27# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
28#
29# RCS: @(#) $Id: loadICU.tcl,v 1.3 2007/04/20 02:23:35 kennykb Exp $
30#
31#----------------------------------------------------------------------
32
33# Calculate the Chinese numerals from zero to ninety-nine.
34
35set zhDigits [list {} \u4e00 \u4e8c \u4e09 \u56db \
36                  \u4e94 \u516d \u4e03 \u516b \u4e5d]
37set t 0
38foreach zt $zhDigits {
39    if { $t == 0 } {
40        set zt {}
41    } elseif { $t == 10 } {
42        set zt \u5341
43    } else {
44        append zt \u5341
45    }
46    set d 0
47    foreach zd $zhDigits {
48        if { $t == 0 && $d == 0 } {
49            set zd \u3007
50        } elseif { $t == 20 && $d != 0 } {
51            set zt \u5eff
52        } elseif { $t == 30 && $d != 0 } {
53            set zt \u5345
54        }
55        lappend zhNumbers $zt$zd
56        incr d
57    }
58    incr t 10
59}
60
61# Set format overrides for various locales.
62
63set format(zh,LOCALE_NUMERALS) $zhNumbers
64set format(ja,LOCALE_ERAS) [list \
65                                [list -9223372036854775808 \u897f\u66a6 0 ] \
66                                [list -3061011600 \u660e\u6cbb 1867] \
67                                [list -1812186000 \u5927\u6b63 1911] \
68                                [list -1357635600 \u662d\u548c 1925] \
69                                [list 600220800 \u5e73\u6210 1988]]
70set format(zh,LOCALE_DATE_FORMAT) "\u516c\u5143%Y\u5e74%B%Od\u65E5"
71set format(ja,LOCALE_DATE_FORMAT) "%EY\u5e74%m\u6708%d\u65E5"
72set format(ko,LOCALE_DATE_FORMAT) "%Y\ub144%B%Od\uc77c"
73set format(zh,LOCALE_TIME_FORMAT) "%OH\u65f6%OM\u5206%OS\u79d2"
74set format(ja,LOCALE_TIME_FORMAT) "%H\u6642%M\u5206%S\u79d2"
75set format(ko,LOCALE_TIME_FORMAT) "%H\uc2dc%M\ubd84%S\ucd08"
76set format(zh,LOCALE_DATE_TIME_FORMAT) "%A %Y\u5e74%B%Od\u65E5%OH\u65f6%OM\u5206%OS\u79d2 %z"
77set format(ja,LOCALE_DATE_TIME_FORMAT) "%EY\u5e74%m\u6708%d\u65E5 (%a) %H\u6642%M\u5206%S\u79d2 %z"
78set format(ko,LOCALE_DATE_TIME_FORMAT) "%A %Y\ub144%B%Od\uc77c%H\uc2dc%M\ubd84%S\ucd08 %z"
79set format(ja,TIME_FORMAT_12) {%P %I:%M:%S}
80
81# The next set of format overrides were obtained from the glibc
82# localization strings.
83
84set format(cs_CZ,DATE_FORMAT) %d.%m.%Y
85set format(cs_CZ,DATE_TIME_FORMAT) {%a %e. %B %Y, %H:%M:%S %z}
86set format(cs_CZ,TIME_FORMAT) %H:%M:%S
87set format(cs_CZ,TIME_FORMAT_12) %I:%M:%S
88set format(da_DK,DATE_FORMAT) %d-%m-%Y
89set format(da_DK,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
90set format(da_DK,TIME_FORMAT) %T
91set format(da_DK,TIME_FORMAT_12) %T
92set format(de_AT,DATE_FORMAT) %Y-%m-%d
93set format(de_AT,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
94set format(de_AT,TIME_FORMAT) %T
95set format(de_AT,TIME_FORMAT_12) %T
96set format(de_BE,DATE_FORMAT) %Y-%m-%d
97set format(de_BE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
98set format(de_BE,TIME_FORMAT) %T
99set format(de_BE,TIME_FORMAT_12) %T
100set format(de_CH,DATE_FORMAT) %Y-%m-%d
101set format(de_CH,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
102set format(de_CH,TIME_FORMAT) %T
103set format(de_CH,TIME_FORMAT_12) %T
104set format(de_DE,DATE_FORMAT) %Y-%m-%d
105set format(de_DE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
106set format(de_DE,TIME_FORMAT) %T
107set format(de_DE,TIME_FORMAT_12) %T
108set format(de_LU,DATE_FORMAT) %Y-%m-%d
109set format(de_LU,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
110set format(de_LU,TIME_FORMAT) %T
111set format(de_LU,TIME_FORMAT_12) %T
112set format(en_CA,DATE_FORMAT) %d/%m/%y
113set format(en_CA,DATE_TIME_FORMAT) {%a %d %b %Y %r %z}
114set format(en_CA,TIME_FORMAT) %r
115set format(en_CA,TIME_FORMAT_12) {%I:%M:%S %p}
116set format(en_DK,DATE_FORMAT) %Y-%m-%d
117set format(en_DK,DATE_TIME_FORMAT) {%Y-%m-%dT%T %z}
118set format(en_DK,TIME_FORMAT) %T
119set format(en_DK,TIME_FORMAT_12) %T
120set format(en_GB,DATE_FORMAT) %d/%m/%y
121set format(en_GB,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
122set format(en_GB,TIME_FORMAT) %T
123set format(en_GB,TIME_FORMAT_12) %T
124set format(en_IE,DATE_FORMAT) %d/%m/%y
125set format(en_IE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
126set format(en_IE,TIME_FORMAT) %T
127set format(en_IE,TIME_FORMAT_12) %T
128set format(en_US,DATE_FORMAT) %m/%d/%y
129set format(en_US,DATE_TIME_FORMAT) {%a %d %b %Y %r %z}
130set format(en_US,TIME_FORMAT) %r
131set format(en_US,TIME_FORMAT_12) {%I:%M:%S %p}
132set format(es_ES,DATE_FORMAT) %d/%m/%y
133set format(es_ES,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
134set format(es_ES,TIME_FORMAT) %T
135set format(es_ES,TIME_FORMAT_12) %T
136set format(et_EE,DATE_FORMAT) %d.%m.%Y
137set format(et_EE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
138set format(et_EE,TIME_FORMAT) %T
139set format(et_EE,TIME_FORMAT_12) %T
140set format(eu_ES,DATE_FORMAT) {%a, %Yeko %bren %da}
141set format(eu_ES,DATE_TIME_FORMAT) {%y-%m-%d %T %z}
142set format(eu_ES,TIME_FORMAT) %T
143set format(eu_ES,TIME_FORMAT_12) %T
144set format(fi_FI,DATE_FORMAT) %d.%m.%Y
145set format(fi_FI,DATE_TIME_FORMAT) {%a %e %B %Y %T}
146set format(fi_FI,TIME_FORMAT) %T
147set format(fi_FI,TIME_FORMAT_12) %T
148set format(fo_FO,DATE_FORMAT) %d/%m-%Y
149set format(fo_FO,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
150set format(fo_FO,TIME_FORMAT) %T
151set format(fo_FO,TIME_FORMAT_12) %T
152set format(fr_BE,DATE_FORMAT) %d/%m/%y
153set format(fr_BE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
154set format(fr_BE,TIME_FORMAT) %T
155set format(fr_BE,TIME_FORMAT_12) %T
156set format(fr_CA,DATE_FORMAT) %Y-%m-%d
157set format(fr_CA,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
158set format(fr_CA,TIME_FORMAT) %T
159set format(fr_CA,TIME_FORMAT_12) %T
160set format(fr_CH,DATE_FORMAT) {%d. %m. %y}
161set format(fr_CH,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
162set format(fr_CH,TIME_FORMAT) %T
163set format(fr_CH,TIME_FORMAT_12) %T
164set format(fr_FR,DATE_FORMAT) %d.%m.%Y
165set format(fr_FR,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
166set format(fr_FR,TIME_FORMAT) %T
167set format(fr_FR,TIME_FORMAT_12) %T
168set format(fr_LU,DATE_FORMAT) %d.%m.%Y
169set format(fr_LU,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
170set format(fr_LU,TIME_FORMAT) %T
171set format(fr_LU,TIME_FORMAT_12) %T
172set format(ga_IE,DATE_FORMAT) %d.%m.%y
173set format(ga_IE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
174set format(ga_IE,TIME_FORMAT) %T
175set format(ga_IE,TIME_FORMAT_12) %T
176set format(gr_GR,DATE_FORMAT) %d/%m/%Y
177set format(gr_GR,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
178set format(gr_GR,TIME_FORMAT) %T
179set format(gr_GR,TIME_FORMAT_12) %T
180set format(hr_HR,DATE_FORMAT) %d.%m.%y
181set format(hr_HR,DATE_TIME_FORMAT) {%a %d %b %Y %T}
182set format(hr_HR,TIME_FORMAT) %T
183set format(hr_HR,TIME_FORMAT_12) %T
184set format(hu_HU,DATE_FORMAT) %Y-%m-%d
185set format(hu_HU,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
186set format(hu_HU,TIME_FORMAT) %T
187set format(hu_HU,TIME_FORMAT_12) %T
188set format(is_IS,DATE_FORMAT) {%a %e.%b %Y}
189set format(is_IS,DATE_TIME_FORMAT) {%a %e.%b %Y, %T %z}
190set format(is_IS,TIME_FORMAT) %T
191set format(is_IS,TIME_FORMAT_12) %T
192set format(it_IT,DATE_FORMAT) %d/%m/%Y
193set format(it_IT,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
194set format(it_IT,TIME_FORMAT) %T
195set format(it_IT,TIME_FORMAT_12) %T
196set format(iw_IL,DATE_FORMAT) %d/%m/%y
197set format(iw_IL,DATE_TIME_FORMAT) {%z %H:%M:%S %Y %b %d %a}
198set format(iw_IL,TIME_FORMAT) %H:%M:%S
199set format(iw_IL,TIME_FORMAT_12) {%I:%M:%S %P}
200set format(kl_GL,DATE_FORMAT) {%d %b %Y}
201set format(kl_GL,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
202set format(kl_GL,TIME_FORMAT) %T
203set format(kl_GL,TIME_FORMAT_12) %T
204set format(lt_LT,DATE_FORMAT) %Y.%m.%d
205set format(lt_LT,DATE_TIME_FORMAT) {%Y m. %B %d d. %T}
206set format(lt_LT,TIME_FORMAT) %T
207set format(lt_LT,TIME_FORMAT_12) %T
208set format(lv_LV,DATE_FORMAT) %Y.%m.%d.
209set format(lv_LV,DATE_TIME_FORMAT) {%A, %Y. gada %e. %B, plkst. %H un %M}
210set format(lv_LV,TIME_FORMAT) %T
211set format(lv_LV,TIME_FORMAT_12) %T
212set format(nl_BE,DATE_FORMAT) %d-%m-%y
213set format(nl_BE,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
214set format(nl_BE,TIME_FORMAT) %T
215set format(nl_BE,TIME_FORMAT_12) %T
216set format(nl_NL,DATE_FORMAT) %d-%m-%y
217set format(nl_NL,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
218set format(nl_NL,TIME_FORMAT) %T
219set format(nl_NL,TIME_FORMAT_12) %T
220set format(no_NO,DATE_FORMAT) %d-%m-%Y
221set format(no_NO,DATE_TIME_FORMAT) {%a %d-%m-%Y %T %z}
222set format(no_NO,TIME_FORMAT) %T
223set format(no_NO,TIME_FORMAT_12) %T
224set format(pl_PL,DATE_FORMAT) %Y-%m-%d
225set format(pl_PL,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
226set format(pl_PL,TIME_FORMAT) %T
227set format(pl_PL,TIME_FORMAT_12) %T
228set format(pt_BR,DATE_FORMAT) %d-%m-%Y
229set format(pt_BR,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
230set format(pt_BR,TIME_FORMAT) %T
231set format(pt_BR,TIME_FORMAT_12) %T
232set format(pt_PT,DATE_FORMAT) %d-%m-%Y
233set format(pt_PT,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
234set format(pt_PT,TIME_FORMAT) %T
235set format(pt_PT,TIME_FORMAT_12) %T
236set format(ro_RO,DATE_FORMAT) %Y-%m-%d
237set format(ro_RO,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
238set format(ro_RO,TIME_FORMAT) %T
239set format(ro_RO,TIME_FORMAT_12) %T
240set format(ru_RU,DATE_FORMAT) %d.%m.%Y
241set format(ru_RU,DATE_TIME_FORMAT) {%a %d %b %Y %T}
242set format(ru_RU,TIME_FORMAT) %T
243set format(ru_RU,TIME_FORMAT_12) %T
244set format(sl_SI,DATE_FORMAT) %d.%m.%Y
245set format(sl_SI,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
246set format(sl_SI,TIME_FORMAT) %T
247set format(sl_SI,TIME_FORMAT_12) %T
248set format(sv_FI,DATE_FORMAT) %Y-%m-%d
249set format(sv_FI,DATE_TIME_FORMAT) {%a %e %b %Y %H.%M.%S}
250set format(sv_FI,TIME_FORMAT) %H.%M.%S
251set format(sv_FI,TIME_FORMAT_12) %H.%M.%S
252set format(sv_SE,DATE_FORMAT) %Y-%m-%d
253set format(sv_SE,DATE_TIME_FORMAT) {%a %e %b %Y %H.%M.%S}
254set format(sv_SE,TIME_FORMAT) %H.%M.%S
255set format(sv_SE,TIME_FORMAT_12) %H.%M.%S
256set format(tr_TR,DATE_FORMAT) %Y-%m-%d
257set format(tr_TR,DATE_TIME_FORMAT) {%a %d %b %Y %T %z}
258set format(tr_TR,TIME_FORMAT) %T
259set format(tr_TR,TIME_FORMAT_12) %T
260
261#----------------------------------------------------------------------
262#
263# handleLocaleFile --
264#
265#       Extracts strings from an ICU locale definition.
266#
267# Parameters:
268#       localeName - Name of the locale (e.g., de_AT_euro)
269#       fileName - Name of the file containing the data
270#       msgFileName - Name of the file containing the Tcl message catalog
271#
272# Results:
273#       None.
274#
275# Side effects:
276#       Writes the Tcl message catalog.
277#
278#----------------------------------------------------------------------
279
280proc handleLocaleFile { localeName fileName msgFileName } {
281    variable format
282
283    # Get the content of the ICU file
284
285    set f [open $fileName r]
286    fconfigure $f -encoding utf-8
287    set data [read $f]
288    close $f
289
290    # Parse the ICU data
291
292    set state {}
293    foreach line [split $data \n] {
294        switch -exact -- $state {
295            {} {
296
297                # Look for the beginnings of data blocks
298
299                switch -regexp -- $line {
300                    {^[[:space:]]*AmPmMarkers[[:space:]]+[\{]} {
301                        set state data
302                        set key AmPmMarkers
303                    }
304                    {^[[:space:]]*DateTimePatterns[[:space:]]+[\{]} {
305                        set state data
306                        set key DateTimePatterns
307                    }
308                    {^[[:space:]]*DayAbbreviations[[:space:]]+[\{]} {
309                        set state data
310                        set key DayAbbreviations
311                    }
312                    {^[[:space:]]*DayNames[[:space:]]+[\{]} {
313                        set state data
314                        set key DayNames
315                    }
316                    {^[[:space:]]*Eras[[:space:]]+[\{]} {
317                        set state data
318                        set key Eras
319                    }
320                    {^[[:space:]]*MonthAbbreviations[[:space:]]+[\{]} {
321                        set state data
322                        set key MonthAbbreviations
323                    }
324                    {^[[:space:]]*MonthNames[[:space:]]+[\{]} {
325                        set state data
326                        set key MonthNames
327                    }
328                }
329            }
330            data {
331
332
333                # Inside a data block, collect the strings, doing backslash
334                # expansion to pick up the Unicodes
335
336                if { [regexp {"(.*)",} $line -> item] } {
337                    lappend items($key) [subst -nocommands -novariables $item]
338                } elseif { [regexp {^[[:space:]]*[\}][[:space:]]*$} $line] } {
339                    set state {}
340                }
341            }
342        }
343    }
344
345    # Skip locales that don't change time strings.
346
347    if {![array exists items]} return
348
349    # Write the Tcl message catalog
350
351    set f [open $msgFileName w]
352
353    # Write a header
354
355    puts $f "\# created by $::argv0 -- do not edit"
356    puts $f "namespace eval ::tcl::clock \{"
357
358    # Do ordinary sets of strings (weekday and month names)
359
360    foreach key {
361        DayAbbreviations DayNames MonthAbbreviations MonthNames
362    } tkey {
363        DAYS_OF_WEEK_ABBREV DAYS_OF_WEEK_FULL
364        MONTHS_ABBREV MONTHS_FULL
365    } {
366        if { [info exists items($key)] } {
367            set itemList $items($key)
368            set cmd1 "    ::msgcat::mcset "
369            append cmd1 $localeName " " $tkey " \[list "
370            foreach item $itemList {
371                append cmd1 \\\n {        } \" [backslashify $item] \"
372            }
373            append cmd1 \]
374            puts $f $cmd1
375        }
376    }
377
378    # Do the eras, B.C.E., and C.E.
379
380    if { [info exists items(Eras)] } {
381        foreach { bce ce } $items(Eras) break
382        set cmd "    ::msgcat::mcset "
383        append cmd $localeName " " BCE " \"" [backslashify $bce] \"
384        puts $f $cmd
385        set cmd "    ::msgcat::mcset "
386        append cmd $localeName " " CE " \"" [backslashify $ce] \"
387        puts $f $cmd
388    }
389
390    # Do the AM and PM markers
391
392    if { [info exists items(AmPmMarkers)] } {
393        foreach { am pm } $items(AmPmMarkers) break
394        set cmd "    ::msgcat::mcset "
395        append cmd $localeName " " AM " \"" [backslashify $am] \"
396        puts $f $cmd
397        set cmd "    ::msgcat::mcset "
398        append cmd $localeName " " PM " \"" [backslashify $pm] \"
399        puts $f $cmd
400    }
401
402    # Do the date/time patterns. First date...
403
404    if { [info exists format($localeName,DATE_FORMAT)]
405         || [info exists items(DateTimePatterns)] } {
406
407        # Find the shortest date format that includes a 4-digit year.
408
409        if { ![info exists format($localeName,DATE_FORMAT)] } {
410            for { set i 7 } { $i >= 4 } { incr i -1 } {
411                if { [regexp yyyy [lindex $items(DateTimePatterns) $i]] } {
412                    break
413                }
414            }
415            set fmt \
416                [backslashify \
417                     [percentify [lindex $items(DateTimePatterns) $i]]]
418            set format($localeName,DATE_FORMAT) $fmt
419        }
420
421        # Put it to the message catalog
422
423        set cmd "    ::msgcat::mcset "
424        append cmd $localeName " DATE_FORMAT \"" \
425            $format($localeName,DATE_FORMAT) "\""
426        puts $f $cmd
427    }
428
429    # Time
430
431    if { [info exists format($localeName,TIME_FORMAT)]
432         || [info exists items(DateTimePatterns)] } {
433
434        # Find the shortest time pattern that includes the seconds
435
436        if { ![info exists format($localeName,TIME_FORMAT)] } {
437            for { set i 3 } { $i >= 0 } { incr i -1 } {
438                if { [regexp H [lindex $items(DateTimePatterns) $i]] 
439                     && [regexp s [lindex $items(DateTimePatterns) $i]] } {
440                    break
441                }
442            }
443            if { $i >= 0 } {
444                set fmt \
445                    [backslashify \
446                         [percentify [lindex $items(DateTimePatterns) $i]]]
447                regsub { %Z} $fmt {} format($localeName,TIME_FORMAT)
448            }
449        }
450
451        # Put it to the message catalog
452
453        if { [info exists format($localeName,TIME_FORMAT)] } {
454            set cmd "    ::msgcat::mcset "
455            append cmd $localeName " TIME_FORMAT \"" \
456                $format($localeName,TIME_FORMAT) "\""
457            puts $f $cmd
458        }
459    }
460
461    # 12-hour time...
462
463    if { [info exists format($localeName,TIME_FORMAT_12)]
464         || [info exists items(DateTimePatterns)] } {
465
466        # Shortest patterm with 12-hour time that includes seconds
467
468        if { ![info exists format($localeName,TIME_FORMAT_12)] } {
469            for { set i 3 } { $i >= 0 } { incr i -1 } {
470                if { [regexp h [lindex $items(DateTimePatterns) $i]] 
471                     && [regexp s [lindex $items(DateTimePatterns) $i]] } {
472                    break
473                }
474            }
475            if { $i >= 0 } {
476                set fmt \
477                    [backslashify \
478                         [percentify [lindex $items(DateTimePatterns) $i]]]
479                regsub { %Z} $fmt {} format($localeName,TIME_FORMAT_12)
480            }
481        }
482
483        # Put it to the catalog
484
485        if { [info exists format($localeName,TIME_FORMAT_12)] } {
486            set cmd "    ::msgcat::mcset "
487            append cmd $localeName " TIME_FORMAT_12 \"" \
488                $format($localeName,TIME_FORMAT_12) "\""
489            puts $f $cmd
490        }
491    }
492
493    # Date and time... Prefer 24-hour format to 12-hour format.
494
495    if { ![info exists format($localeName,DATE_TIME_FORMAT)] 
496         && [info exists format($localeName,DATE_FORMAT)]
497         && [info exists format($localeName,TIME_FORMAT)]} {
498        set format($localeName,DATE_TIME_FORMAT) \
499            $format($localeName,DATE_FORMAT)
500        append format($localeName,DATE_TIME_FORMAT) \
501            " " $format($localeName,TIME_FORMAT) " %z"
502    }
503    if { ![info exists format($localeName,DATE_TIME_FORMAT)] 
504         && [info exists format($localeName,DATE_FORMAT)]
505         && [info exists format($localeName,TIME_FORMAT_12)]} {
506        set format($localeName,DATE_TIME_FORMAT) \
507            $format($localeName,DATE_FORMAT)
508        append format($localeName,DATE_TIME_FORMAT) \
509            " " $format($localeName,TIME_FORMAT_12) " %z"
510    }
511
512    # Write date/time format to the file
513
514    if { [info exists format($localeName,DATE_TIME_FORMAT)] } {
515        set cmd "    ::msgcat::mcset "
516        append cmd $localeName " DATE_TIME_FORMAT \"" \
517            $format($localeName,DATE_TIME_FORMAT) "\""
518        puts $f $cmd
519    }
520
521    # Write the string sets to the file.
522
523    foreach key { 
524        LOCALE_NUMERALS LOCALE_DATE_FORMAT LOCALE_TIME_FORMAT
525        LOCALE_DATE_TIME_FORMAT LOCALE_ERAS LOCALE_YEAR_FORMAT
526    } {
527        if { [info exists format($localeName,$key)] } {
528            set cmd "    ::msgcat::mcset "
529            append cmd $localeName " " $key " \"" \
530                [backslashify $format($localeName,$key)] "\""
531            puts $f $cmd
532        }
533    }
534
535    # Footer
536
537    puts $f "\}"
538    close $f
539}
540
541#----------------------------------------------------------------------
542#
543# percentify --
544#
545#       Converts a Java/ICU-style time format to a C/Tcl style one.
546#
547# Parameters:
548#       string -- Format to convert
549#
550# Results:
551#       Returns the converted format.
552#
553# Side effects:
554#       None.
555#
556#----------------------------------------------------------------------
557
558proc percentify { string } {
559    set retval {}
560    foreach { unquoted quoted } [split $string '] {
561        append retval [string map {
562            EEEE %A MMMM %B yyyy %Y
563            MMM %b EEE %a
564            dd %d hh %I HH %H mm %M MM %m ss %S yy %y
565            a %P d %e h %l H %k M %m z %z
566        } $unquoted]
567        append retval $quoted
568    }
569    return $retval
570}
571
572#----------------------------------------------------------------------
573#
574# backslashify --
575#
576#       Converts a UTF-8 string to a plain ASCII one with escapes.
577#
578# Parameters:
579#       string -- String to convert
580#
581# Results:
582#       Returns the converted string
583#
584# Side effects:
585#       None.
586#
587#----------------------------------------------------------------------
588
589proc backslashify { string } {
590
591    set retval {}
592    foreach char [split $string {}] {
593        scan $char %c ccode
594        if { $ccode >= 0x0020 && $ccode < 0x007f
595             && $char ne "\{" && $char ne "\}" && $char ne "\["
596             && $char ne "\]" && $char ne "\\" && $char ne "\$" } {
597            append retval $char
598        } else {
599            append retval \\u [format %04x $ccode]
600        }
601    }
602    return $retval
603}
604
605#----------------------------------------------------------------------
606#
607# MAIN PROGRAM
608#
609#----------------------------------------------------------------------
610
611# Extract directories from command line
612
613foreach { icudir msgdir } $argv break
614
615# Walk the ICU files and create corresponding Tcl message catalogs
616
617foreach fileName [glob -directory $icudir *.txt] {
618    set n [file rootname [file tail $fileName]]
619    if { [regexp {^[a-z]{2,3}(_[A-Z]{2,3}(_.*)?)?$} $n] } {
620        handleLocaleFile $n $fileName [file join $msgdir [string tolower $n].msg]
621    }
622}
Note: See TracBrowser for help on using the repository browser.