\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#404: Let Message Catalogs get the Locale from their File Name}
\date{July 17, 2011}
\author{Harald Oehlmann}
\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 \#404}&\textbf{Let Message Catalogs get the Locale from their File Name}\\\hline
Author&

Harald Oehlmann \tipmail{harald.oehlmann}{elmicron.de}
\\
Created&Sunday, \(\text{17}^{\text{th}}\) July 2011\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.9 $\\
Keywords&msgcat, convention\\
Post History&\\
Discussions To&Tcl Core list\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

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

\section{Rationale}

Current message catalog files are as follows:
\begin{itemize}
\item{}
Catalog file name: \textit{\tiplangle{}locale\tiprangle{}} \textbf{.msg}
\item{}
Catalog folder: technically any, recommended: msgs in package main folder. Must be specified to the command \textbf{mcload}.
\item{}
Catalog file contents: one command per translated item:
\begingroup\small\begin{verbatim}
        msgcat::mcset locale ori ?translation?
\end{verbatim}
\endgroup
\end{itemize}

Example with \tiplangle{}locale\tiprangle{} equal ``de'':
\begingroup\small\begin{verbatim}
-de.msg-
::msgcat::mcset de Open Öffnen
::msgcat::mcset de Close Schliessen
-eof-
\end{verbatim}
\endgroup

The same locale value (de) is contained in the file name and in each \textbf{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 \textbf{mcset} command.

The scope of this TIP is a new command similar to \textbf{mcset} which determines the locale from the file name.

IMHO it makes no sense to specify the locale of \textbf{mcset} commands and the locale in the file name different and thus separately.

\section{Specification}

\subsection{mc file locale}

The \textbf{mc file locale} is a locale specified by the file name of a message file.

Example:

\begin{quote}
Message catalogue file name: \textbf{de\_ch.msg}
\end{quote}

\begin{quote}
mc file locale: de\_ch
\end{quote}

The package \textbf{msgcat} maintains one value, \textbf{mc file locale}, with the following properties:
\begin{itemize}
\item{}
Its initial value is "" (the root locale).
\item{}
Before a message catalog file is sourced by the procedure \textbf{::msgcat::mcload}, the \textbf{mc file locale} is extracted from the message file name and stored as the current value.
\item{}
The \textbf{mc file locale} may be querried by the command \textbf{::msgcat::mcconfig -mcfilelocale}.
\item{}
The \textbf{mc file locale} may also be set by the command \textbf{::msgcat::mcconfig -mcfilelocale value}.
\item{}
The original message filename may \textit{not} be reconstructed by: \textbf{[::msgcat::mcconfig -mcfilelocale].msg}; there can be case differences.
\end{itemize}

The command \textbf{::msgcat::mcconfig} is shared with \cite{tip399}. It has a new option \textbf{-mcfilelocale}.

\subsection{New Commands}

There are two new commands:
\begin{itemize}
\item{}
\textbf{::msgcat::mcflset} \textit{source} ?\textit{translation}?
\item{}
\textbf{::msgcat::mcflmset} \textit{list}
\end{itemize}

These work as:
\begingroup\small\begin{verbatim}
   ::msgcat::mcset [::msgcat::mcconfig -mcfilelocale] source ?translation?
   ::msgcat::mcmset [::msgcat::mcconfig -mcfilelocale] list
\end{verbatim}
\endgroup

The command name \textbf{mcflset} is an abreviation of: ``\textbf{m}essage \textbf{c'atalogue with }f\textbf{ile }l\textbf{ocale }set\('''\)''.

\section{Example Usages}

The example of the Rationale section above may now be written as:
\begingroup\small\begin{verbatim}
-de.msg-
::msgcat::mcflset Open Öffnen
::msgcat::mcflset Close Schliessen
-eof-
\end{verbatim}
\endgroup

The locale value \textbf{de} only appears in the file name.

Further examples are in the tcl wiki msgcat page: [\url{http://wiki.tcl.tk/msgcat}]

\section{Reference Implementation}

See Tcl Feature Request 3544988. [\url{http://sourceforge.net/support/tracker.php/?aid=3544988}]

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\begin{thebibliography}{TIP \#1}
\addcontentsline{toc}{section}{References}
\bibitem[TIP \#399]{tip399}
Harald Oehlmann,
\emph{Dynamic Locale Changing for msgcat},
on-line at \url{http://purl.org/tcl/tip/399.html}
\end{thebibliography}
\end{document}
