summaryrefslogtreecommitdiffstats
path: root/library/msgcat1.0/msgcat.tcl
diff options
context:
space:
mode:
authorericm <ericm>2000-07-17 22:25:25 (GMT)
committerericm <ericm>2000-07-17 22:25:25 (GMT)
commite58ac604378b855c137c05576fd796df952cb349 (patch)
tree4aaf12e0f958eefbadbedaafe08b0bd0d6340cbe /library/msgcat1.0/msgcat.tcl
parent247225ff4ff6cee54489ee55dc9911d459e1003d (diff)
downloadtcl-e58ac604378b855c137c05576fd796df952cb349.zip
tcl-e58ac604378b855c137c05576fd796df952cb349.tar.gz
tcl-e58ac604378b855c137c05576fd796df952cb349.tar.bz2
* library/msgcat1.0/msgcat.tcl:
* doc/msgcat.n: * tests/msgcat.test: Applied patches from Chris Nelson, to provide the mcmset function, which allows the translator to set multiple string translations in a single function call, rather than requiring many calls to mcset. [RFE: 6000, 5993]. In addition, these patches correct mcload to use utf-8 encoding on when reading message catalog files, and provides for better default behavior for determining the locale on a Windows system.
Diffstat (limited to 'library/msgcat1.0/msgcat.tcl')
-rw-r--r--library/msgcat1.0/msgcat.tcl88
1 files changed, 84 insertions, 4 deletions
diff --git a/library/msgcat1.0/msgcat.tcl b/library/msgcat1.0/msgcat.tcl
index fb1aeb3..fa3350c 100644
--- a/library/msgcat1.0/msgcat.tcl
+++ b/library/msgcat1.0/msgcat.tcl
@@ -10,12 +10,12 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: msgcat.tcl,v 1.6 2000/07/06 21:05:02 ericm Exp $
+# RCS: @(#) $Id: msgcat.tcl,v 1.7 2000/07/17 22:25:26 ericm Exp $
package provide msgcat 1.1
namespace eval msgcat {
- namespace export mc mcset mclocale mcpreferences mcunknown mcmax
+ namespace export mc mcset mcmset mclocale mcpreferences mcunknown mcmax
# Records the current locale as passed to mclocale
variable locale ""
@@ -134,7 +134,10 @@ proc msgcat::mcload {langdir} {
set langfile [file join $langdir $p.msg]
if {[file exists $langfile]} {
incr x
- uplevel [list source $langfile]
+ set fid [open $langfile "r"]
+ fconfigure $fid -encoding utf-8
+ uplevel [list eval [read $fid]]
+ close $fid
}
}
return $x
@@ -164,6 +167,34 @@ proc msgcat::mcset {locale src {dest ""}} {
return $dest
}
+# msgcat::mcmset --
+#
+# Set the translation for multiple strings in a specified locale.
+#
+# Arguments:
+# locale The locale to use.
+# pairs One or more src/dest pairs (must be even length)
+#
+# Results:
+# Returns the number of pairs processed
+
+proc msgcat::mcmset {locale pairs } {
+
+ set length [llength $pairs]
+ if {$length % 2} {
+ error {bad translation list: should be "mcmset locale {src dest ...}"}
+ }
+
+ set locale [string tolower $locale]
+ set ns [uplevel {namespace current}]
+
+ foreach {src dest} $pairs {
+ set ::msgcat::msgs($locale,$ns,$src) $dest
+ }
+
+ return $length
+}
+
# msgcat::mcunknown --
#
# This routine is called by msgcat::mc if a translation cannot
@@ -218,6 +249,55 @@ namespace eval msgcat {
if {[info exists ::env(LANG)]} {
mclocale $::env(LANG)
} else {
- mclocale "C"
+ if { $tcl_platform(platform) == "windows" } {
+ # try to set locale depending on registry settings
+ #
+ set key {HKEY_CURRENT_USER\Control Panel\International}
+ if {[catch {package require registry}] || \
+ [catch {registry get $key "locale"} locale]} {
+ mclocale "C"
+ } else {
+
+ package forget registry
+ #
+ # Clean up registry value for translating LCID value
+ # by using only the last 2 digits, since first
+ # 2 digits appear to be the country... For example
+ # 0409 - English - United States
+ # 0809 - English - United Kingdom
+ #
+ set locale [string trimleft $locale "0"]
+ set locale [string range $locale end-1 end]
+ set locale [string tolower $locale]
+ switch -- $locale {
+ 01 { mclocale "ar" }
+ 02 { mclocale "bg" }
+ 03 { mclocale "ca" }
+ 04 { mclocale "zh" }
+ 05 { mclocale "cs" }
+ 06 { mclocale "da" }
+ 07 { mclocale "de" }
+ 08 { mclocale "el" }
+ 09 { mclocale "en" }
+ 0a { mclocale "es" }
+ 0b { mclocale "fi" }
+ 0c { mclocale "fr" }
+ 0d { mclocale "he" }
+ 0e { mclocale "hu" }
+ 0f { mclocale "is" }
+ 10 { mclocale "it" }
+ 11 { mclocale "ja" }
+ 12 { mclocale "ko" }
+ 13 { mclocale "da" }
+ 14 { mclocale "no" }
+ 15 { mclocale "pl" }
+ 16 { mclocale "pt" }
+
+ default { mclocale "C" }
+ }
+ }
+ } else {
+ mclocale "C"
+ }
}
}