TIP 156: Language-Neutral Root Locale for Msgcat

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:		Kevin Kenny <kennykb@acm.org>
State:		Final
Type:		Project
Vote:		Done
Created:	20-Sep-2003
Tcl-Version:	8.5
Discussions-To:	news:comp.lang.tcl
Post-History:	

Abstract

This TIP proposes to extend Tcl's message catalog mechanism by adding a "root locale" (whose name is the empty string) that is searched after searches in all the language-dependent locales have failed.

Rationale

In the current message catalog system, the search key for localized strings is a version of the string itself, expressed in either a language-neutral form or in the natural language of the programmer. This scheme has the advantage that when a program searches for a localized message, the search will always succeed; if a translation of the message cannot be found in any of the message catalog preferences, at least a language-neutral string (or a string in an inappropriate language) will be available.

The drawback to the scheme as it stands comes when ambiguities enter into the picture. For instance, the English word, 'file,' might, depending on context, appear in French as the word 'fichier,' or the word, 'râpe.' An application implementing a catalog of hand tools might well encounter such an ambiguity.

A more specific example that I have encountered deals with date and time formatting. Consider the [clock format] command. It accepts a format group, %x, that formats the current date in the default format for the current locale. It also accepts a group, %D, that formats the current date in the specific format %m/%d/%Y. In both the 'C' locale and the 'en_US' locale, these two format groups generate identical strings. If the message catalog is used to store them, there has to be a way to have distinct keys look up the same string in the language-neutral default locale.

Specification

The solution that both Java and ICU use for managing the problem of ambiguity in the default locale is to implement a "root locale" that is searched after the searches in the current language-dependent locales have failed. If a translation is found in the "root locale", it is used just as if it was found in a language-dependent locale.

This TIP proposes the same for Tcl. Specifically, it proposes that.

  1. The msgcat::mcpreferences command will be modified to add the empty string as a list element after the elements corresponding to the current locale. If the current locale, for instance, is en_US_funky, the result of [mcpreferences] will be {en_US_funky en_US en {}}, and if the current locale is de_CH_schwyzertuetsch, the four locales to be searched will be:

    * de_CH_schwyzertuetsch

    * de_CH

    * de

    * {} (the empty locale)

  2. The msgcat::mcload command will be modified so that if it encounters the empty string as a locale name, it will replace it with ROOT. This modification is made so that the empty locale will correspond to a file named, "ROOT.msg" rather than just ".msg", and hence yield a file whose name does not begin with a period. Files whose names begin with periods are treated specially on certain filesystems (for instance, on Unix, they become files hidden from the ls command), and avoiding such names seems wise. The implementors of both Java and ICU have made the same decision.

Reference Implementation

The changes require to implement this proposal are minimal and can be obtained from SourceForge as Tcl Patch #809825.

Copyright

Copyright © 2003 by Kevin B. Kenny. All rights reserved.

Permission to use this document in accordance with the terms of Open Publication License (http://www.opencontent.org/openpub/\) is herewith granted.

History