Tcl Source Code

Artifact [90264f6afd]
Login

Artifact 90264f6afd4df8c335c6b4ac7808f92bafdcc5b5:

Attachment "msgcat-1.4.5rc0-1.5.0.diff" to ticket [3511941fff] added by oehhar 2012-07-17 15:51:23.
--- C:/Program Files/tcl8.5/lib/tcl8/8.5/msgcat-1.4.5.tm	Mon Jul 02 14:31:26 2012
+++ C:/Program Files/tcl8.5/lib/tcl8/8.5/msgcat-1.5.0.tm	Mon Jul 16 16:05:56 2012
@@ -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.4.5
+package provide msgcat 1.5.0
 
 namespace eval msgcat {
-    namespace export mc mcload mclocale mcmax mcmset mcpreferences mcset \
-	    mcunknown
+    namespace export mcconfig mc mcload mclocale mcmax mcmset mcpreferences \
+	    mcset mcunknown
 
     # Records the current locale as passed to mclocale
     variable Locale ""
@@ -25,6 +25,9 @@
     # Records the list of locales to search
     variable Loclist {}
 
+    # 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 "<locale> <namespace> <src>", where locale and
     # namespace should be themselves dict values and the value is
@@ -163,6 +166,38 @@
     }
 }
 
+# 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
+    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
@@ -277,16 +312,19 @@
 #	Returns the number of message catalogs that were loaded.
 
 proc msgcat::mcload {langdir} {
+    variable Patternlist
     set x 0
-    foreach p [mcpreferences] {
-	if { $p eq {} } {
-	    set p ROOT
-	}
-	set langfile [file join $langdir $p.msg]
-	if {[file exists $langfile]} {
-	    incr x
-	    uplevel 1 [list ::source -encoding utf-8 $langfile]
+    set filelist {}
+    foreach pattern [lsort -unique [concat [mcpreferences] $Patternlist]] {
+	if { $pattern eq {} } {
+	    set pattern ROOT
 	}
+	lappend filelist {*}[glob -directory $langdir -nocomplain -types {f r}\
+		-- $pattern.msg]
+    }
+    foreach langfile [lsort -unique $filelist] {
+	incr x
+	uplevel 1 [list ::source -encoding utf-8 $langfile]
     }
     return $x
 }