10

I am busy with a new document class and I have been trying my hand in internationalizing some of the contents. I have tried using translator from Beamer. Is this a good strategy? Can the code shown below be improved? Are there any other options to carry out such a task?

%% The article class
\documentclass[oneside]{book}
\usepackage[paperwidth=4.75in,paperheight=7.25in,
            textwidth=4.5in,textheight=6.5in,
            headsep=0.1in, footskip=0.15in,
            marginratio=1:1]{geometry}
\usepackage[dutch,greek,english]{babel}
\usepackage{filecontents,xspace}
\usepackage{translator}

%% just to allow filenames to be changed easily
\def\fname{mothererror}

%% The Greek dictionary file
\begin{filecontents*}{\fname-Greek.dict}
\ProvidesDictionary{\fname}{Greek}
\providetranslation{mother}{mht`era `olwn t`wn laj`wn}
\providetranslation{Error}{L`ajos}
\providetranslation{Errors}{L`ajh}
\end{filecontents*}

%% The Dutch dictionary file
\begin{filecontents*}{\fname-Dutch.dict}
\ProvidesDictionary{\fname}{Dutch}
\providetranslation{mother}{moeder van alle fouten}
\providetranslation{error}{fout}
\providetranslation{Error}{Fout}
\providetranslation{Errors}{Fouten}
\end{filecontents*}

%% The English dictionary file
\begin{filecontents*}{\fname-English.dict}
\ProvidesDictionary{\fname}{English}
\providetranslation{mother}{mother of all errors}
\providetranslation{error}{error}
\providetranslation{Error}{Error}
\providetranslation{Errors}{Errors}
\end{filecontents*}

%% The package file mothererror.sty
%% internationlizes mother of all errors!
\begin{filecontents*}{\fname.sty}
%% Now declare what environment we need:
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
%% Load the translator package
\RequirePackage{translator}
\usedictionary{\fname}
%% create a test error for package
\def\geterror#1{\translate{Error} #1 : 
\ifcase #1\or 
    1 A general error\or
    \ldots\translate{mother}\xspace\or
 \fi}
\end{filecontents*}

%% Load the package we just saved
\usepackage{\fname}
\uselanguage{dutch,greek,english}
\begin{document}
%% Dutch
\selectlanguage{dutch}
\chapter{\translate{Errors}}
Dutch: \geterror{2}, \today
%% English
\selectlanguage{english}
\chapter{Errors}
English: \geterror{2},  \today
%% Greek
\selectlanguage{greek}
\chapter{\translate{Errors}}
Ellhnik'a: \geterror{2} \today
\end{document}
8

An alternative would be, to use package scrbase from KOMA-Script. It seems the chapter about this package is missing at scrguien.pdf. Here is an example:

\documentclass[oneside]{book}
\usepackage[paperwidth=4.75in,paperheight=7.25in,
  textwidth=4.5in,textheight=6.5in, headsep=0.1in, footskip=0.15in,
  marginratio=1:1]{geometry} 
\usepackage[dutch,greek,english]{babel}
\usepackage{filecontents,xspace} 
\usepackage{scrbase}

\begin{filecontents*}{mothererror.sty}
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{mothererror}[2011/11/01 v0.1 demo package]
\RequirePackage{xspace} 
\AtBeginDocument{%
  \providecaptionname{english}\mothername{mother}%
  \providecaptionname{english}\errorname{error}%
  \providecaptionname{english}\errorsname{errors}%
  \providecaptionname{greek}\mothername{mht`era `olwn t`wn laj`wn}%
  \providecaptionname{greek}\errorname{L`ajos}%
  \providecaptionname{greek}\errorsname{L`ajh}%
  \providecaptionname{dutch}\mothername{moeder van alle fouten}%
  \providecaptionname{dutch}\errorname{fout}%
  \providecaptionname{dutch}\errorsname{fouten}% 
}

\def\geterror#1{\expandafter\MakeUppercase\errorname~#1:  
  \ifcase #1
    \PackageError{mothererror}{unknown error number #1!}{}%
  \or
    A general error\or \ldots\mothername\xspace
  \else 
    \PackageError{mothererror}{unknown error number #1!}{}%
  \fi 
}
\endinput
\end{filecontents*}

%% Load the package we just saved 
\usepackage{mothererror}

\begin{document}
\tableofcontents %% Dutch 
\selectlanguage{dutch}
\chapter{\expandafter\MakeUppercase\errorsname} 
Dutch: \geterror{2},
\today 
%% English 
\selectlanguage{english}
\chapter{\expandafter\MakeUppercase\errorsname} 
English: \geterror{2},
\today 
%% Greek \selectlanguage{greek}
\chapter{\expandafter\MakeUppercase\errorsname} 
Ellhnik'a: \geterror{2}
\today
\end{document}

There are also commands \newcaptionname and \renewcaptionname.

BTW: I've use \expandafter\MakeUppercase to change the case of the first letter of a term. So you need terms like "error" only once instead of twice. It's only a little trick, but it's often useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.