Index: changes ================================================================== --- changes +++ changes @@ -8839,5 +8839,7 @@ => http 2.8.12 2017-09-02 (bug)[0e4d88] replace command, delete trace kills namespace (porter) --- Released 8.7a1, September 8, 2017 --- http://core.tcl.tk/tcl/ for details + +2017-12-11 (TIP 490) add oo support for msgcat (fellows) Index: doc/msgcat.n ================================================================== --- doc/msgcat.n +++ doc/msgcat.n @@ -48,10 +48,12 @@ .sp \fB::msgcat::mcpackageconfig subcommand\fR \fIoption\fR ?\fIvalue\fR? .sp \fB::msgcat::mcforgetpackage\fR .VE "TIP 412" +.sp +\fBmixin msgcat::MessageCatalogAware\fR .BE .SH DESCRIPTION .PP The \fBmsgcat\fR package provides a set of functions that can be used to manage multi-lingual user interfaces. @@ -229,10 +231,30 @@ .TP \fB::msgcat::mcforgetpackage\fR . The calling package clears all its state within the \fBmsgcat\fR package including all settings and translations. .VE "TIP 412" +.RE +.TP +.VS "TIP 490" +\fBmixin msgcat::MessageCatalogAware\fR +. +A class within a package should include this line to make message catalog commands (mc, mcmax, mcexists) work. +.PP +.CS +namespace eval ::foo { + msgcat::mcload $dir/msgs + oo::class create Foo { + mixin msgcat::MessageCatalogAware + + method printMessage {x y} { + puts [my mc "FooPrintMessage(%d,%d)" $x $y] + } + } +} +package provide foo 1.0 .CE +.VE "TIP 490" .PP .SH "LOCALE SPECIFICATION" .PP The locale is specified to \fBmsgcat\fR by a locale string passed to \fB::msgcat::mclocale\fR. Index: library/msgcat/msgcat.tcl ================================================================== --- library/msgcat/msgcat.tcl +++ library/msgcat/msgcat.tcl @@ -12,11 +12,11 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 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.6.1 +package provide msgcat 1.6.2 namespace eval msgcat { namespace export mc mcexists mcload mclocale mcmax mcmset mcpreferences mcset\ mcunknown mcflset mcflmset mcloadedlocales mcforgetpackage\ mcpackageconfig mcpackagelocale @@ -1104,10 +1104,37 @@ append ret _$modifier } return $ret } +# Make oo classes message catalog aware +namespace eval ::msgcat { + oo::class create MessageCatalogAware { + forward mc ::msgcat::OOBridge ::msgcat::mc + forward mcmax ::msgcat::OOBridge ::msgcat::mcmax + forward mcexists ::msgcat::OOBridge ::msgcat::mcexists + # Tricky point: methods are not usefully callable from outside the + # class hierarchy + unexport mc mcmax mcexists + } +} + +# helper function to find package namespace and evaluate mc commands within +# this namespace +proc ::msgcat::OOBridge {cmd args} { + if {[catch { + # Tricky point: [self class] needs to run in the caller + set ns [namespace qualifiers [uplevel 1 {self class}]] + }]} { + # Not a class-defined method (so we got an error); use instance instead + set ns [namespace qualifiers [uplevel 1 self]] + } + apply [list {cmd args} {$cmd {*}$args} $ns] $cmd {*}$args + # DKF: alternative - one may give a better error trace + # namespace eval ::$ns [list $cmd {*}$args] +} + # Initialize the default locale proc msgcat::Init {} { global env # Index: library/msgcat/pkgIndex.tcl ================================================================== --- library/msgcat/pkgIndex.tcl +++ library/msgcat/pkgIndex.tcl @@ -1,2 +1,2 @@ if {![package vsatisfies [package provide Tcl] 8.5-]} {return} -package ifneeded msgcat 1.6.1 [list source [file join $dir msgcat.tcl]] +package ifneeded msgcat 2.6.2 [list source [file join $dir msgcat.tcl]] Index: unix/Makefile.in ================================================================== --- unix/Makefile.in +++ unix/Makefile.in @@ -853,12 +853,12 @@ @echo "Installing package opt0.4 files to $(SCRIPT_INSTALL_DIR)/opt0.4/"; @for i in $(TOP_DIR)/library/opt/*.tcl ; \ do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ done; - @echo "Installing package msgcat 1.6.1 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.1.tm; + @echo "Installing package msgcat 1.6.2 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.2.tm; @echo "Installing package tcltest 2.4.1 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/tcltest/tcltest.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/tcltest-2.4.1.tm; @echo "Installing package platform 1.0.14 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/platform/platform.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.4/platform-1.0.14.tm; Index: win/Makefile.in ================================================================== --- win/Makefile.in +++ win/Makefile.in @@ -662,12 +662,12 @@ @echo "Installing library opt0.4 directory"; @for j in $(ROOT_DIR)/library/opt/*.tcl; \ do \ $(COPY) "$$j" "$(SCRIPT_INSTALL_DIR)/opt0.4"; \ done; - @echo "Installing package msgcat 1.6.1 as a Tcl Module"; - @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.1.tm; + @echo "Installing package msgcat 1.6.2 as a Tcl Module"; + @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.2.tm; @echo "Installing package tcltest 2.4.0 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/tcltest/tcltest.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/tcltest-2.4.0.tm; @echo "Installing package platform 1.0.14 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/platform/platform.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.4/platform-1.0.14.tm; @echo "Installing package platform::shell 1.1.4 as a Tcl Module";