TIP #404: LET MESSAGE CATALOGS GET THE LOCALE FROM THEIR FILE NAME ==================================================================== Version: $Revision: 1.9 $ Author: Harald Oehlmann State: Final Type: Project Tcl-Version: 8.6 Vote: Done Created: Sunday, 17 July 2011 URL: https://tip.tcl-lang.org404.html Discussions-To: Tcl Core list Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP proposes a mechanism for coupling locales more strongly to the names of the files that define them, an already-recommended practice, so as to make it less error-prone to produce message catalogs. RATIONALE =========== Current message catalog files are as follows: * Catalog file name: // *.msg* * Catalog folder: technically any, recommended: msgs in package main folder. Must be specified to the command *mcload*. * Catalog file contents: one command per translated item: msgcat::mcset locale ori ?translation? Example with equal "de": -de.msg- ::msgcat::mcset de Open Öffnen ::msgcat::mcset de Close Schliessen -eof- The same locale value (de) is contained in the file name and in each *mcset* command. This is technically unnecessary and error-prone. I found myself often copying message file contents from one language to the next and not setting the right locale in each *mcset* command. The scope of this TIP is a new command similar to *mcset* which determines the locale from the file name. IMHO it makes no sense to specify the locale of *mcset* commands and the locale in the file name different and thus separately. SPECIFICATION =============== MC FILE LOCALE ---------------- The *mc file locale* is a locale specified by the file name of a message file. Example: Message catalogue file name: *de_ch.msg* mc file locale: de_ch The package *msgcat* maintains one value, *mc file locale*, with the following properties: * Its initial value is "" (the root locale). * Before a message catalog file is sourced by the procedure *::msgcat::mcload*, the *mc file locale* is extracted from the message file name and stored as the current value. * The *mc file locale* may be querried by the command *::msgcat::mcconfig -mcfilelocale*. * The *mc file locale* may also be set by the command *::msgcat::mcconfig -mcfilelocale value*. * The original message filename may /not/ be reconstructed by: *[::msgcat::mcconfig -mcfilelocale].msg*; there can be case differences. The command *::msgcat::mcconfig* is shared with [TIP #399]. It has a new option *-mcfilelocale*. NEW COMMANDS -------------- There are two new commands: * *::msgcat::mcflset* /source/ ?/translation/? * *::msgcat::mcflmset* /list/ These work as: ::msgcat::mcset [::msgcat::mcconfig -mcfilelocale] source ?translation? ::msgcat::mcmset [::msgcat::mcconfig -mcfilelocale] list The command name *mcflset* is an abreviation of: "*m*essage *c'atalogue with *f*ile *l*ocale *set*". EXAMPLE USAGES ================ The example of the Rationale section above may now be written as: -de.msg- ::msgcat::mcflset Open Öffnen ::msgcat::mcflset Close Schliessen -eof- The locale value *de* only appears in the file name. Further examples are in the tcl wiki msgcat page: [] REFERENCE IMPLEMENTATION ========================== See Tcl Feature Request 3544988. [] COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows