From c2423634f23817171376e31b484153c6949f63d8 Mon Sep 17 00:00:00 2001 From: oehhar Date: Wed, 19 Sep 2012 20:31:48 +0000 Subject: TIP#399 implementation: mcconfig may add additional glob pattern for mcload --- ChangeLog | 9 ++++++ changes | 2 ++ library/msgcat/msgcat.tcl | 67 +++++++++++++++++++++++++++++++++++---------- library/msgcat/pkgIndex.tcl | 2 +- unix/Makefile.in | 4 +-- win/Makefile.in | 4 +-- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a17845..8ba37af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-09-19 Harald Oehlmann + + IMPLEMENTATION OF TIP#399. + + * library/msgcat/msgcat.tcl: [FRQ 3544988]: New commands [mcconfig] + * library/msgcat/pkgIndex.tcl: to set additional mcload search pattern. + * unix/Makefile.in: Bump to 1.6.0. + * win/Makefile.in: + 2012-09-19 Jan Nijtmans * generic/tcl.h: make Tcl_Interp a fully opaque structure diff --git a/changes b/changes index b902445..f4c501d 100644 --- a/changes +++ b/changes @@ -8116,3 +8116,5 @@ Many revisions to better support a Cygwin environment (nijtmans) Dropped support for OS X versions less than 10.4 (Tiger) (fellows) --- Released 8.6b3, September 18, 2012 --- See ChangeLog for details --- + +2012-09-19 (TIP399) New msgcat command [mcconfig] (oehlmann) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 112507a..42c8f20 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -13,11 +13,11 @@ package require Tcl 8.5 # When the version number changes, be sure to update the pkgIndex.tcl file, # and the installation directory in the Makefiles. -package provide msgcat 1.5.0 +package provide msgcat 1.6.0 namespace eval msgcat { namespace export mc mcload mclocale mcmax mcmset mcpreferences mcset \ - mcunknown mcflset mcflmset + mcunknown mcflset mcflmset mcconfig # Records the current locale as passed to mclocale variable Locale "" @@ -28,6 +28,9 @@ namespace eval msgcat { # Records the locale of the currently sourced message catalogue file variable FileLocale + # List of file pattern to load in addition to Loclist. + variable Patternlist {} + # Records the mapping between source strings and translated strings. The # dict key is of the form " ", where locale and # namespace should be themselves dict values and the value is @@ -166,6 +169,39 @@ namespace eval msgcat { } } +# msgcat::mcconfig option ?value? ?option? ?value? +# +# Get or set a package option. +# To set options, one may specify multiple option-value pairs. +# To read an option value, one may specify a single option. +# Available options are: +# -pattern +# List of file pattern to load in addition to mcpreferences +# +# Arguments: +# option The name of the option +# value The new value of the option +# +# Results: +# The value if options are read + +proc msgcat::mcconfig {args} { + variable Patternlist + variable MCFileLocale + if {1 == [llength $args]} { + switch -exact -- [lindex $args] { + -pattern { return $Patternlist} + default { return -code error "Unknown option" } + } + } + dict for {option value} $args { + switch -exact -- $option { + -pattern { set Patternlist $value } + default { return -code error "Unknown option" } + } + } +} + # msgcat::mc -- # # Find the translation for the given string based on the current @@ -280,26 +316,29 @@ proc msgcat::mcpreferences {} { # Returns the number of message catalogs that were loaded. proc msgcat::mcload {langdir} { + variable Patternlist variable FileLocale # Save the file locale if we are recursively called if {[info exists FileLocale]} { set nestedFileLocale $FileLocale } set x 0 - foreach p [mcpreferences] { - if { $p eq {} } { - set p ROOT + set filelist {} + foreach pattern [lsort -unique [concat [mcpreferences] $Patternlist]] { + if { $pattern eq {} } { + set pattern ROOT } - set langfile [file join $langdir $p.msg] - if {[file exists $langfile]} { - incr x - set FileLocale [string tolower [file tail [file rootname $langfile]]] - if {"root" eq $FileLocale} { - set FileLocale "" - } - uplevel 1 [list ::source -encoding utf-8 $langfile] - unset FileLocale + lappend filelist {*}[glob -directory $langdir -nocomplain -types {f r}\ + -- $pattern.msg] + } + foreach langfile [lsort -unique $filelist] { + incr x + set FileLocale [string tolower [file tail [file rootname $langfile]]] + if {"root" eq $FileLocale} { + set FileLocale "" } + uplevel 1 [list ::source -encoding utf-8 $langfile] + unset FileLocale } if {[info exists nestedFileLocale]} { set FileLocale $nestedFileLocale diff --git a/library/msgcat/pkgIndex.tcl b/library/msgcat/pkgIndex.tcl index 832bf81..7399c92 100644 --- a/library/msgcat/pkgIndex.tcl +++ b/library/msgcat/pkgIndex.tcl @@ -1,2 +1,2 @@ if {![package vsatisfies [package provide Tcl] 8.5]} {return} -package ifneeded msgcat 1.5.0 [list source [file join $dir msgcat.tcl]] +package ifneeded msgcat 1.6.0 [list source [file join $dir msgcat.tcl]] diff --git a/unix/Makefile.in b/unix/Makefile.in index 9ac84f7..aa1820e 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -846,8 +846,8 @@ install-libraries: libraries do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ done; - @echo "Installing package msgcat 1.5.0 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.5.0.tm; + @echo "Installing package msgcat 1.6.0 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.0.tm; @echo "Installing package tcltest 2.3.4 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/tcltest/tcltest.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/tcltest-2.3.4.tm; diff --git a/win/Makefile.in b/win/Makefile.in index bef71c0..8ea4f0a 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -647,8 +647,8 @@ install-libraries: libraries install-tzdata install-msgs do \ $(COPY) "$$j" "$(SCRIPT_INSTALL_DIR)/opt0.4"; \ done; - @echo "Installing package msgcat 1.5.0 as a Tcl Module"; - @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.5.0.tm; + @echo "Installing package msgcat 1.6.0 as a Tcl Module"; + @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.0.tm; @echo "Installing package tcltest 2.3.4 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/tcltest/tcltest.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/tcltest-2.3.4.tm; @echo "Installing package platform 1.0.10 as a Tcl Module"; -- cgit v0.12 From 496eb965fff74d179633477de87a6b8b72113c14 Mon Sep 17 00:00:00 2001 From: oehhar Date: Wed, 19 Sep 2012 20:40:14 +0000 Subject: (proposal) msgcat with dynamic mc file load on locale change --- ChangeLog | 8 +- changes | 2 +- library/msgcat/msgcat.tcl | 723 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 623 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ba37af..9920962 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,7 @@ 2012-09-19 Harald Oehlmann - IMPLEMENTATION OF TIP#399. - - * library/msgcat/msgcat.tcl: [FRQ 3544988]: New commands [mcconfig] - * library/msgcat/pkgIndex.tcl: to set additional mcload search pattern. - * unix/Makefile.in: Bump to 1.6.0. - * win/Makefile.in: + * library/msgcat/msgcat.tcl: dynamic locale change with mc file + load on locale change. 2012-09-19 Jan Nijtmans diff --git a/changes b/changes index f4c501d..b6cacf5 100644 --- a/changes +++ b/changes @@ -8117,4 +8117,4 @@ Dropped support for OS X versions less than 10.4 (Tiger) (fellows) --- Released 8.6b3, September 18, 2012 --- See ChangeLog for details --- -2012-09-19 (TIP399) New msgcat command [mcconfig] (oehlmann) +2012-09-19 (feature proposal) msgcat dynamic locale change (oehlmann) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 42c8f20..c35803f 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -16,23 +16,28 @@ package require Tcl 8.5 package provide msgcat 1.6.0 namespace eval msgcat { - namespace export mc mcload mclocale mcmax mcmset mcpreferences mcset \ - mcunknown mcflset mcflmset mcconfig - - # Records the current locale as passed to mclocale - variable Locale "" + namespace export mc mcexists mcload mclocale mcmax mcmset\ + mcpreferences mcset mcunknown mcflset mcflmset\ + mcloadedlocales mcforgetpackage\ + mcpackageconfig mcpackagelocale # Records the list of locales to search variable Loclist {} + # List of currently loaded locales + variable LoadedLocales {} + # Records the locale of the currently sourced message catalogue file variable FileLocale - # List of file pattern to load in addition to Loclist. - variable Patternlist {} + # Configuration values per Package (e.g. client namespace). + # The dict key is of the form "