Overview
| Artifact ID: | ee3447d72d8d2a963f257dcb8425d0cd7c2cbb21 |
|---|---|
| Ticket: | 219106ffffffffffffffffffffffffffffffffff
msgcat performance improvements |
| User & Date: | nobody on 2000-10-26 01:10:53 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
OriginalBugID: 5993 RFE Version: 8.2 SubmitDate: '2000-07-07' LastModified: '2000-07-17' Severity: SER Status: Released Submitter: techsupp ChangedBy: ericm RelatedBugIDs: 6000 OS: All Windows FixedDate: '2000-07-17' FixedInVersion: 8.4a2 ClosedDate: '2000-10-25' Name: Chris Nelson CVS: 1.50 Comments: I've got something like 20 more changes that we've made in 8.2.0 that I hope to get into the 8.4 release. I'm not sure the best way to get there. Will you guys be merging this sort of change down stream into 8.4? DesiredBehavior: 1) msgcat doesn't seem to handle encodings properly 2) multiple calls to mcset are slow 3) msgcat should make reasonable assumptions about locale on Win32 systems Patch: *** msgcat.n.ORIG Fri Jul 7 13:19:13 2000 --- msgcat.n Fri Jul 7 13:26:27 2000 *************** *** 23,28 **** --- 23,30 ---- .sp \fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR? .sp + \fB::msgcat::mcmset \fIlocale src-trans-list\fR + .sp \fB::msgcat::mcunknown \fIlocale src-string\fR .BE *************** *** 83,88 **** --- 85,99 ---- in the specified \fIlocale\fR. If \fItranslate-string\fR is not specified, \fIsrc-string\fR is used for both. The function returns \fItranslate-string\fR. + .TP + \fB::msgcat::mcmset \fIlocale src-trans-list\fR + Sets the translation for multiple source strings in + \fIsrc-trans-list\fR in the specified \fIlocale\fR. + \fIsrc-trans-list\fR must have an even number of elements and is in + the form {\fIsrc-string translate-string\fR ?\fIsrc-string + translate-string ...\fR?} \fBmcsetcat::mcmset\fR can be significantly + faster than multiple invocations of \fBmsgcat::mcset\fR. The function + returns the number of translations set. .TP \fB::msgcat::mcunknown \fIlocale src-string\fR This routine is called by \fB::msgcat::mc\fR in the case when *** msgcat.tcl.ORIG Thu Apr 15 20:47:17 1999 --- msgcat.tcl Fri Jul 7 13:17:26 2000 *************** *** 15,21 **** package provide msgcat 1.0 namespace eval msgcat { ! namespace export mc mcset mclocale mcpreferences mcunknown # Records the current locale as passed to mclocale variable locale "" --- 15,21 ---- package provide msgcat 1.0 namespace eval msgcat { ! namespace export mc mcset mcmset mclocale mcpreferences mcunknown # Records the current locale as passed to mclocale variable locale "" *************** *** 117,123 **** set langfile [file join $langdir $p.msg] if {[file exists $langfile]} { incr x ! uplevel [list source $langfile] } } return $x --- 117,126 ---- set langfile [file join $langdir $p.msg] if {[file exists $langfile]} { incr x ! set fid [open $langfile "r"] ! fconfigure $fid -encoding utf-8 ! uplevel [list eval [read $fid]] ! close $fid } } return $x *************** *** 147,152 **** --- 150,183 ---- 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 *************** *** 169,177 **** namespace eval msgcat { # set default locale, try to get from environment if {[info exists ::env(LANG)]} { mclocale $::env(LANG) } else { ! mclocale "C" } } --- 200,260 ---- namespace eval msgcat { # set default locale, try to get from environment + # if {[info exists ::env(LANG)]} { mclocale $::env(LANG) } else { ! if { $tcl_platform(platform) == "windows" } { ! # try to set locale depending on registry settings ! # ! package require registry ! ! set key {HKEY_CURRENT_USER\Control Panel\International} ! if {[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" ! } } } + PatchFiles: msgcat.n msgcat.tcl This all looks pretty good. I would make one modification, however, which is that rather than introducing a new command [mcmset], I would rather just extend the syntax of [mcset], to support multiple sets at once: mcset en msg1 tr1 msg2 tr2 msg3 tr3 ... What do you think? Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- 07/17/2000 ericm I merged this patch into CVS. Your additions will go out with 8.4a2. Thanks! Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- 07/17/2000 ericm - foundin changed to: "obsolete: 8.2"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "69. Other"
- title changed to: "msgcat performance improvements"
- type changed to: "RFE"