\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#156: Language-Neutral Root Locale for Msgcat}
\date{September 20, 2003}
\author{Kevin Kenny}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#156}&\textbf{Language-Neutral Root Locale for Msgcat}\\\hline
Author&

Kevin Kenny \tipmail{kennykb}{acm.org}
\\
Created&Saturday, \(\text{20}^{\text{th}}\) September 2003\\
Type&Project\\
Tcl Version&\(8.5\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.4 $\\
Post History&\\
Discussions To&news:comp.lang.tcl\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

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.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{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.

\section{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.
\begin{enumerate}
\item{}
The \textit{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 \textit{en\_US\_funky}, the result of [mcpreferences] will be \textit{\{en\_US\_funky en\_US en \{\}\}}, and if the current locale is \textit{de\_CH\_schwyzertuetsch}, the four locales to be searched will be:
\begin{itemize}
\item{}
\textit{de\_CH\_schwyzertuetsch}
\item{}
\textit{de\_CH}
\item{}
\textit{de}
\item{}
\{\} (the empty locale)
\end{itemize}
\setcounter{enumi}{1}
\item{}
The \textit{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 \textit{ls} command), and avoiding such names seems wise. The implementors of both Java and ICU have made the same decision.
\end{enumerate}

\section{Reference Implementation}

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

\section{Copyright}

Copyright (c) 2003 by Kevin B. Kenny. All rights reserved.

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

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
