diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | doc/msgcat.n | 8 | ||||
-rw-r--r-- | library/msgcat/msgcat.tcl | 30 | ||||
-rw-r--r-- | library/msgcat1.0/msgcat.tcl | 30 |
4 files changed, 68 insertions, 8 deletions
@@ -1,3 +1,11 @@ +2000-06-29 Eric Melski <ericm@scriptics.com> + + * doc/msgcat.n: Doc's for mcmax function. + + * library/msgcat1.0/msgcat.tcl: Applied patches from Laurent + Duperval, to add mcmax function, which computes the length of the + longest of several translated strings. Bumped version number to 1.1. + 2000-06-27 Eric Melski <ericm@scriptics.com> * tests/stringObj.test: Tweaked tests to avoid hardcoded diff --git a/doc/msgcat.n b/doc/msgcat.n index f4acd54..e271839 100644 --- a/doc/msgcat.n +++ b/doc/msgcat.n @@ -15,6 +15,8 @@ msgcat \- Tcl message catalog .SH SYNOPSIS \fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR? .sp +\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR? +.sp \fB::msgcat::mclocale \fR?\fInewLocale\fR? .sp \fB::msgcat::mcpreferences\fR @@ -63,6 +65,12 @@ use the result. If an application is written for a single language in this fashion, then it is easy to add support for additional languages later simply by defining new message catalog entries. .TP +\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR? +Given several source strings, \fB::msgcat::mcmax\fR returns the length +of the longest translated string. This is useful when designing +localized GUI's, which may require that all buttons, for example, be a +fixed width (which will be the width of the widest button). +.TP \fB::msgcat::mclocale \fR?\fInewLocale\fR? This function sets the locale to \fInewLocale\fR. If \fInewLocale\fR is omitted, the current locale is returned, otherwise the current locale diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 4619ae1..0f7d6d3 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -4,18 +4,18 @@ # message catalog facility for Tcl programs. It should be # loaded with the command "package require msgcat". # -# Copyright (c) 1998 by Scriptics Corporation. +# Copyright (c) 1998-2000 by Ajuba Solutions. # Copyright (c) 1998 by Mark Harrison. # # 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.4 2000/04/11 21:16:18 ericm Exp $ +# RCS: @(#) $Id: msgcat.tcl,v 1.5 2000/06/30 06:28:27 ericm Exp $ -package provide msgcat 1.0 +package provide msgcat 1.1 namespace eval msgcat { - namespace export mc mcset mclocale mcpreferences mcunknown + namespace export mc mcset mclocale mcpreferences mcunknown mcmax # Records the current locale as passed to mclocale variable locale "" @@ -182,6 +182,28 @@ proc msgcat::mcunknown {locale src} { return $src } +# msgcat::mcmax -- +# +# Calculates the maximun length of the translated strings of the given +# list. +# +# Arguments: +# args strings to translate. +# +# Results: +# Returns the length of the longest translated string. + +proc msgcat::mcmax {args} { + set max 0 + foreach string $args { + set len [string length [msgcat::mc $string]] + if {$len>$max} { + set max $len + } + } + return $max +} + # Initialize the default locale namespace eval msgcat { diff --git a/library/msgcat1.0/msgcat.tcl b/library/msgcat1.0/msgcat.tcl index 4619ae1..0f7d6d3 100644 --- a/library/msgcat1.0/msgcat.tcl +++ b/library/msgcat1.0/msgcat.tcl @@ -4,18 +4,18 @@ # message catalog facility for Tcl programs. It should be # loaded with the command "package require msgcat". # -# Copyright (c) 1998 by Scriptics Corporation. +# Copyright (c) 1998-2000 by Ajuba Solutions. # Copyright (c) 1998 by Mark Harrison. # # 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.4 2000/04/11 21:16:18 ericm Exp $ +# RCS: @(#) $Id: msgcat.tcl,v 1.5 2000/06/30 06:28:27 ericm Exp $ -package provide msgcat 1.0 +package provide msgcat 1.1 namespace eval msgcat { - namespace export mc mcset mclocale mcpreferences mcunknown + namespace export mc mcset mclocale mcpreferences mcunknown mcmax # Records the current locale as passed to mclocale variable locale "" @@ -182,6 +182,28 @@ proc msgcat::mcunknown {locale src} { return $src } +# msgcat::mcmax -- +# +# Calculates the maximun length of the translated strings of the given +# list. +# +# Arguments: +# args strings to translate. +# +# Results: +# Returns the length of the longest translated string. + +proc msgcat::mcmax {args} { + set max 0 + foreach string $args { + set len [string length [msgcat::mc $string]] + if {$len>$max} { + set max $len + } + } + return $max +} + # Initialize the default locale namespace eval msgcat { |