| 1 |
% arara: pdflatex: { shell: on, interaction: nonstopmode } |
| 2 |
% arara: biber |
| 3 |
% arara: pdflatex: { interaction: nonstopmode } |
| 4 |
% arara: pdflatex: { interaction: nonstopmode } |
| 5 |
% -------------------------------------------------------------------------- |
| 6 |
% the TRANSLATIONS package |
| 7 |
% |
| 8 |
% internationalizations of LaTeX2e packages |
| 9 |
% |
| 10 |
% -------------------------------------------------------------------------- |
| 11 |
% Clemens Niederberger |
| 12 |
% Web: https://github.com/cgnieder/translations |
| 13 |
% E-Mail: [email protected] |
| 14 |
% -------------------------------------------------------------------------- |
| 15 |
% Copyright 2012--2022 Clemens Niederberger |
| 16 |
% |
| 17 |
% This work may be distributed and/or modified under the |
| 18 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 19 |
% of this license or (at your option) any later version. |
| 20 |
% The latest version of this license is in |
| 21 |
% http://www.latex-project.org/lppl.txt |
| 22 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 23 |
% version 2008/05/04 or later. |
| 24 |
% |
| 25 |
% The Current Maintainer of this work is Clemens Niederberger. |
| 26 |
% -------------------------------------------------------------------------- |
| 27 |
\PassOptionsToPackage{french,brazil,spanish,ngerman,english}{babel} |
| 28 |
\documentclass[load-preamble]{cnltx-doc} |
| 29 |
% ---------------------------------------------------------------------------- |
| 30 |
\usepackage{imakeidx} |
| 31 |
% document layout and typographic features |
| 32 |
\setcnltx{ |
| 33 |
package = {translations} , |
| 34 |
authors = Clemens Niederberger , |
| 35 |
email = [email protected] , |
| 36 |
url = https://github.com/cgnieder/translations , |
| 37 |
info = {Internationalization of \LaTeXe\ Packages} , |
| 38 |
add-cmds = { |
| 39 |
baselanguage, |
| 40 |
DeclareDictTranslation, |
| 41 |
DeclareLanguage, |
| 42 |
DeclareLanguageAlias, |
| 43 |
DeclareLanguageDialect, |
| 44 |
DeclareTranslation, |
| 45 |
declaretranslation, |
| 46 |
DeclareTranslationFallback, |
| 47 |
declaretranslationfallback, |
| 48 |
GetTranslation, |
| 49 |
GetTranslationFor, |
| 50 |
ifcurrentbaselang, |
| 51 |
ifcurrentlang, |
| 52 |
IfTranslation, |
| 53 |
LoadDictionary, |
| 54 |
LoadDictionaryFor, |
| 55 |
NewTranslation, |
| 56 |
definetranslation, |
| 57 |
NewTranslationFallback, |
| 58 |
definetranslationfallback, |
| 59 |
ProvideDictionaryFor, |
| 60 |
ProvideDictTranslation, |
| 61 |
ProvideTranslation, |
| 62 |
addtranslation, |
| 63 |
ProvideTranslationFallback, |
| 64 |
addtranslationfallback, |
| 65 |
RenewTranslation, |
| 66 |
redefinetranslation, |
| 67 |
RenewTranslationFallback, |
| 68 |
redefinetranslationfallback, |
| 69 |
SaveTranslation, |
| 70 |
SaveTranslationFor |
| 71 |
} , |
| 72 |
add-silent-cmds = { |
| 73 |
cuisine,kitchen,mypackage@title |
| 74 |
} , |
| 75 |
makeindex-setup = {options={-s cnltx.ist},columns=3,columnsep=1em} , |
| 76 |
index-setup = {othercode=\footnotesize,level=\addsec,noclearpage} |
| 77 |
} |
| 78 |
|
| 79 |
\microtypesetup{tracking=scshape} |
| 80 |
|
| 81 |
\usepackage[ |
| 82 |
backend=biber, |
| 83 |
style=cnltx, |
| 84 |
sortlocale=en_US, |
| 85 |
indexing=cite]{biblatex} |
| 86 |
\usepackage{csquotes} |
| 87 |
\addbibresource{cnltx.bib} |
| 88 |
|
| 89 |
\usepackage[biblatex]{embrac} |
| 90 |
\ChangeEmph{[}[,.02em]{]}[.055em,-.08em] |
| 91 |
\ChangeEmph{(}[-.01em,.04em]{)}[.04em,-.05em] |
| 92 |
|
| 93 |
\defbibheading{bibliography}{\section{References}} |
| 94 |
|
| 95 |
% ---------------------------------------------------------------------------- |
| 96 |
% other packages, bibliography, index |
| 97 |
\usepackage{array,longtable,booktabs} |
| 98 |
\usepackage{hyperref} |
| 99 |
\usepackage[sort]{cleveref} |
| 100 |
|
| 101 |
% ---------------------------------------------------------------------------- |
| 102 |
% example definitions that have to be done in the preamble: |
| 103 |
\DeclareTranslation{English}{Kueche}{kitchen} |
| 104 |
\DeclareTranslation{German}{Kueche}{K\"uche} |
| 105 |
\DeclareTranslation{Spanish}{Kueche}{cocina} |
| 106 |
\DeclareTranslation{French}{Kueche}{cuisine} |
| 107 |
\DeclareTranslation{English}{farbe}{color} |
| 108 |
\DeclareTranslation{British}{farbe}{colour} |
| 109 |
\LoadDictionaryFor{German}{translations-basic-dictionary} |
| 110 |
|
| 111 |
% ---------------------------------------------------------------------------- |
| 112 |
\usepackage{bbding} |
| 113 |
|
| 114 |
\newrobustcmd\fnote[1]{\textsuperscript{#1}} |
| 115 |
|
| 116 |
\tracingmacros=1 |
| 117 |
|
| 118 |
\begin{document} |
| 119 |
|
| 120 |
\section{Motivation} |
| 121 |
This package provides means for package authors to have an easy interface for |
| 122 |
internationalization of their packages. The functionality of this package is |
| 123 |
in many parts also covered by the package |
| 124 |
\pkg{translator}~\cite{pkg:translator} (part of the \pkg*{beamer} bundle). |
| 125 |
Internationalization is also possible with \pkg{babel}~\cite{pkg:babel} and |
| 126 |
it's \cs*{addto}\cs*{captions\meta{language}} mechanism or \KOMAScript's |
| 127 |
\cs*{providecaptionname} and similar commands. However, I believe that |
| 128 |
\translations\ is more flexible than all of these. Unlike \pkg{translator} it |
| 129 |
detects the used (\pkg{babel} or \pkg{polyglossia}~\cite{pkg:polyglossia}) |
| 130 |
language itself and provides expandable retrieving of the translated key. |
| 131 |
\translations\ also provides support for language dialects which means package |
| 132 |
authors can for example distinguish between British, Australian, Canadian and |
| 133 |
US~English. |
| 134 |
|
| 135 |
The first draft of the package was written since I missed an expandable |
| 136 |
version of \pkg{translator}'s \cs*{translate} command. Once I had the |
| 137 |
package available I began using it in various of my other packages so it got |
| 138 |
extended to the needs I faced there. |
| 139 |
|
| 140 |
|
| 141 |
\section{License}\label{sec:license} |
| 142 |
\license |
| 143 |
|
| 144 |
\section{Usage} |
| 145 |
\subsection{Background} |
| 146 |
The \translations\ package enables the author of a package or a class (or a |
| 147 |
document) to declare translations of key words in different languages and |
| 148 |
fetch these translations in the document depending on the active language as |
| 149 |
set by \pkg{babel} or \pkg{polyglossia}. Since \translations\ checks which |
| 150 |
language is active it is generally not necessary (although possible) to |
| 151 |
specify the language for which a translation should be fetched manually. |
| 152 |
|
| 153 |
\translations\ knows of three types of languages: main languages (see |
| 154 |
\cref{tab:languages} on \cpageref{tab:languages}), language dialects (see |
| 155 |
\cref{tab:dialects} on \cpageref{tab:dialects}), and language aliases (see |
| 156 |
\cref{tab:aliases} on \cpageref{tab:aliases}). For the commands declaring or |
| 157 |
fetching a translation base languages and language aliases are equivalent. |
| 158 |
Dialects are similar to aliases but there are important differences. An alias |
| 159 |
can for example be an alias of a dialect. |
| 160 |
|
| 161 |
\Cref{fig:scheme} shows what happens if \translations\ is asked to fetch a |
| 162 |
translation for a given key. |
| 163 |
|
| 164 |
\begin{figure}[htbp] |
| 165 |
\centering |
| 166 |
\newlength\nodewidth |
| 167 |
\setlength\nodewidth{.375\linewidth} |
| 168 |
\newcommand*\yes{\centering\textcolor{green}{\CheckmarkBold}\par} |
| 169 |
\renewcommand*\no{\centering\textcolor{red}{\XSolidBrush}\par} |
| 170 |
\begin{tikzpicture} |
| 171 |
[ |
| 172 |
level/.style={sibling distance=.5\linewidth/#1}, |
| 173 |
every node/.style={ |
| 174 |
draw, |
| 175 |
rounded corners=3pt, |
| 176 |
align=left, |
| 177 |
anchor=north, |
| 178 |
font=\small\sffamily |
| 179 |
} |
| 180 |
] |
| 181 |
\node {check if any\fnote{a} translation is defined in given language} |
| 182 |
child { |
| 183 |
node[text width=\nodewidth] |
| 184 |
{\yes check if language is a dialect} |
| 185 |
child { |
| 186 |
node[text width=\nodewidth/2] |
| 187 |
{\yes check if dialect translation is given} |
| 188 |
child { |
| 189 |
node[text width=\nodewidth/2.75] |
| 190 |
{\yes use dialect translation} |
| 191 |
} |
| 192 |
child { |
| 193 |
node[text width=\nodewidth/2.75] |
| 194 |
{\no use lan\-guage\fnote{b} translation} |
| 195 |
} |
| 196 |
} |
| 197 |
child { |
| 198 |
node[text width=\nodewidth/2] |
| 199 |
{\no use translation}} |
| 200 |
} |
| 201 |
child { |
| 202 |
node[text width=\nodewidth] |
| 203 |
{\no check if fallback translation is given} |
| 204 |
child { |
| 205 |
node[text width=\nodewidth/2.75] |
| 206 |
{\yes use fallback translation} |
| 207 |
} |
| 208 |
child { |
| 209 |
node[text width=\nodewidth/2.75] |
| 210 |
{\no use literal key} |
| 211 |
} |
| 212 |
} ; |
| 213 |
\end{tikzpicture} |
| 214 |
\caption{Schematic representation of \translations' translating |
| 215 |
mechansim. Notes: \fnote{a} except for a possible fallback |
| 216 |
translation. \fnote{b} \ie, the base language of the dialect.} |
| 217 |
\label{fig:scheme} |
| 218 |
\end{figure} |
| 219 |
|
| 220 |
What happens if you declare a translation? There are four cases: |
| 221 |
\begin{enumerate} |
| 222 |
\item You declare a translation for a base language: this is the normal case |
| 223 |
where an internal macro is defined which can be fetched by the |
| 224 |
\cs{GetTranslation} command (see \cref{ssec:commands}). |
| 225 |
\item You declare a translation for a language alias: this is the very same |
| 226 |
as the first case since the same internal macro is defined. |
| 227 |
\item You declare a translation for a dialect: this is two-fold. Either a |
| 228 |
translation for the base language exists so only the translation for the |
| 229 |
dialect is saved. If the translation for the base language does not exist |
| 230 |
it is defined to be the same as the one for the dialect. |
| 231 |
\item You declare a translation for an alias of a dialect: this is the very |
| 232 |
same as the third case as again the internal macros are the same. |
| 233 |
\end{enumerate} |
| 234 |
|
| 235 |
\emph{Beware that if the current language is a language using a non-latin |
| 236 |
font, a translation is missing for said language, and the fallback |
| 237 |
translation needs a Latin script font then \emph{nothing} might be printed.} |
| 238 |
|
| 239 |
\subsection{Available Commands}\label{ssec:commands} |
| 240 |
Below the commands provided by \translations\ are explained. The symbol |
| 241 |
\textcolor{expandable}{\expandablesign} means that the command is expandable. |
| 242 |
Commands without the marker aren't expandable. |
| 243 |
|
| 244 |
\begin{commands} |
| 245 |
\command{DeclareLanguage}[\marg{lang}] |
| 246 |
Declare a language that can be used by \translations. If the language |
| 247 |
already exists it will be silently redefined. This command can only be |
| 248 |
used in the preamble. It should never be necessary to use this command as |
| 249 |
\translations\ already declares loads of languages (\cref{sec:languages}). |
| 250 |
Should you miss one please send me an email and I'll add it to |
| 251 |
\translations. |
| 252 |
\command{DeclareLanguageAlias}[\marg{lang2}\marg{lang1}] |
| 253 |
Declares \meta{lang2} to be an alias of \meta{lang1}. If \meta{lang1} |
| 254 |
doesn't exist yet a warning will be raised and it will be defined. This |
| 255 |
command can only be used in the preamble. It should never be necessary to |
| 256 |
use this command as \translations\ already declares loads of languages |
| 257 |
(\cref{sec:languages}). Should you miss one please send me an email and |
| 258 |
I'll add it to \translations. |
| 259 |
\command{DeclareLanguageDialect}[\marg{dialect}\marg{lang}] |
| 260 |
Declares \meta{dialect} to be a dialect of language \meta{lang}. If a |
| 261 |
translation for \meta{dialect} is provided it is used by the translation |
| 262 |
macros. If there is none the corresponding translation for \meta{lang} |
| 263 |
is used instead. It should never be necessary to use this command as |
| 264 |
\translations\ already declares loads of languages (\cref{sec:languages}). |
| 265 |
Should you miss one please send me an email and I'll add it to |
| 266 |
\translations. |
| 267 |
\command{NewTranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 268 |
Defines a translation of key \meta{key} for the language \meta{lang}. |
| 269 |
An error will be raised if a translation of \meta{key} in language |
| 270 |
\marg{lang} already exists. This command can only be used in the |
| 271 |
preamble. |
| 272 |
\command{NewTranslationFallback}[\marg{key}\marg{translation}] |
| 273 |
\sinceversion{1.4}Defines a fallback translation of key \meta{key} for the |
| 274 |
language \meta{lang}. An error will be raised if a fallback translation of |
| 275 |
\meta{key} already exists. This command can only be used in the preamble. |
| 276 |
\command{RenewTranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 277 |
Redefines a translation of key \meta{key} for the language \meta{lang}. |
| 278 |
An error will be raised if no translation of \meta{key} in language |
| 279 |
\meta{lang} exists. This command can only be used in the preamble. |
| 280 |
\command{RenewTranslationFallback}[\marg{key}\marg{translation}] |
| 281 |
\sinceversion{1.4}Renews a fallback translation. This command can only be |
| 282 |
used in the preamble. |
| 283 |
\command{ProvideTranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 284 |
\sinceversion{1.2}Provides a translation of key \meta{key} for the |
| 285 |
language \meta{lang}. If a translation of \meta{key} in language |
| 286 |
\meta{lang} already exists it won't be overwritten and no error will be |
| 287 |
raised. This command can only be used in the preamble. |
| 288 |
\command{ProvideTranslationFallback}[\marg{key}\marg{translation}] |
| 289 |
\sinceversion{1.4}Provides a fallback translation. This command can only |
| 290 |
be used in the preamble. |
| 291 |
\command{DeclareTranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 292 |
Defines a translation of key \meta{key} for the language \meta{lang}. |
| 293 |
No error will be raised if a translation of \meta{key} already exists. |
| 294 |
This command can only be used in the preamble. |
| 295 |
\command{DeclareTranslationFallback}[\marg{key}\marg{fallback}] |
| 296 |
Declares a fallback translation. This command can only be used in the |
| 297 |
preamble. |
| 298 |
\command{definetranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 299 |
\sinceversion{1.4}A version of \cs{NewTranslation} that \emph{can} be used |
| 300 |
after begin document. |
| 301 |
\command{definetranslationfallback}[\marg{key}\marg{translation}] |
| 302 |
\sinceversion{1.4}A version of \cs{NewTranslationFallback} that \emph{can} |
| 303 |
be used after begin document. |
| 304 |
\command{redefinetranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 305 |
\sinceversion{1.4}A version of \cs{RenewTranslation} that \emph{can} be |
| 306 |
used after begin document. |
| 307 |
\command{redefinetranslationfallback}[\marg{key}\marg{translation}] |
| 308 |
\sinceversion{1.4}A version of \cs{RenewTranslationFallback} that |
| 309 |
\emph{can} be used after begin document. |
| 310 |
\command{addtranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 311 |
\sinceversion{1.4}A version of \cs{ProvideTranslation} that \emph{can} be |
| 312 |
used after begin document. |
| 313 |
\command{addtranslationfallback}[\marg{key}\marg{translation}] |
| 314 |
\sinceversion{1.4}A version of \cs{ProvideTranslationFallback} that |
| 315 |
\emph{can} be used after begin document. |
| 316 |
\command{declaretranslation}[\marg{lang}\marg{key}\marg{translation}] |
| 317 |
\sinceversion{1.4}A version of \cs{DeclareTranslation} that \emph{can} be |
| 318 |
used after begin document. |
| 319 |
\command{declaretranslationfallback}[\marg{key}\marg{translation}] |
| 320 |
\sinceversion{1.4}A version of \cs{DeclareTranslationFallback} that |
| 321 |
\emph{can} be used after begin document. |
| 322 |
\expandable\command{IfTranslation}[\marg{lang}\marg{key}\marg{true}\marg{false}] |
| 323 |
Checks\sinceversion{1.2d} if a translation for \meta{key} in language |
| 324 |
\meta{lang} is defined or not and either leaves \meta{true} or |
| 325 |
\meta{false} in the input stream. |
| 326 |
\expandable\command{GetTranslationFor}[\marg{lang}\marg{key}] |
| 327 |
Fetches and prints the translation of \meta{key} for the language |
| 328 |
\meta{lang}. This command is expandable. |
| 329 |
\expandable\command{GetTranslation}[\marg{key}] |
| 330 |
Fetches and prints the translation of \meta{key} for the currently active |
| 331 |
language (as for example set by \pkg{babel}). This command is expandable. |
| 332 |
\expandable\command{GetLCTranslationFor}[\marg{lang}\marg{key}] |
| 333 |
\sinceversion{1.1}Fetches and prints the translation of \meta{key} for |
| 334 |
the language \meta{lang}. This command ensures that the fetched |
| 335 |
translation is set lowercase. This command is expandable (well, sort |
| 336 |
of: in an \cs*{edef} it leaves \cs*{lowercase}\marg{translation} in the |
| 337 |
input stream where \meta{translation} is what \cs{GetTranslationFor} would |
| 338 |
expand to). |
| 339 |
\expandable\command{GetLCTranslation}[\marg{key}] |
| 340 |
\sinceversion{1.1}Fetches and prints the translation of \meta{key} for |
| 341 |
the currently active language (as for example set by \pkg{babel}). This |
| 342 |
command ensures that the fetched translation is set lowercase. This |
| 343 |
command is expandable (well, sort of: in an \cs*{edef} it leaves |
| 344 |
\cs*{lowercase}\marg{translation} in the input stream where |
| 345 |
\meta{translation} is what \cs{GetTranslation} would expand to). |
| 346 |
\command{GetTranslationForWarn}[\marg{lang}\marg{key}] |
| 347 |
\sinceversion{1.0}Fetches and prints the translation of \meta{key} for |
| 348 |
the language \meta{lang}. Issues a warning if no translation is |
| 349 |
available at the cost of expandability. |
| 350 |
\command{GetTranslationWarn}[\marg{key}] |
| 351 |
\sinceversion{1.0}Fetches and prints the translation of \meta{key} for |
| 352 |
the currently active language (as for example set by \pkg{babel}). |
| 353 |
Issues a warning if no translation is available at the cost of |
| 354 |
expandability. |
| 355 |
\command{GetLCTranslationForWarn}[\marg{lang}\marg{key}] |
| 356 |
\sinceversion{1.1}Fetches and prints the translation of \meta{key} for |
| 357 |
the language \meta{lang}. This command ensures that the fetched |
| 358 |
translation is set lowercase. Issues a warning if no translation is |
| 359 |
available at the cost of expandability. |
| 360 |
\command{GetLCTranslationWarn}[\marg{key}] |
| 361 |
\sinceversion{1.1}Fetches and prints the translation of \meta{key} for |
| 362 |
the currently active language (as for example set by \pkg{babel}). This |
| 363 |
command ensures that the fetched translation is set lowercase. Issues a |
| 364 |
warning if no translation is available at the cost of expandability. |
| 365 |
\command{SaveTranslationFor}[\marg{cmd}\marg{lang}\marg{key}] |
| 366 |
Fetches and saves the translation of \meta{key} for the language |
| 367 |
\meta{lang} in the macro \meta{cmd}. |
| 368 |
\command{SaveTranslation}[\marg{cmd}\marg{key}] |
| 369 |
Fetches and saves the translation of \meta{key} for the currently active |
| 370 |
language (as for example set by \pkg{babel}) in the macro \meta{cmd}. |
| 371 |
\command{LoadDictionary}[\marg{name}] |
| 372 |
Loads a file named \code{\meta{name}-\meta{lang}.trsl} where \meta{lang} |
| 373 |
corresponds to the lowercase name of the current language as defined with |
| 374 |
\cs{DeclareLanguage}. This file should contain the translations for the |
| 375 |
specified language. |
| 376 |
\command{LoadDictionaryFor}[\marg{lang}\marg{name}] |
| 377 |
Loads a file named \code{\meta{name}-\meta{lang}.trsl}. |
| 378 |
\command{NewDictTranslation}[\marg{key}\marg{translation}] |
| 379 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 380 |
picks up the language of that file. Issues an error if either the |
| 381 |
translation for the \meta{key} or the dictionary entry for the \meta{key} |
| 382 |
already exists. |
| 383 |
\command{RenewDictTranslation}[\marg{key}\marg{translation}] |
| 384 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 385 |
picks up the language of that file. Issues an error if either the |
| 386 |
translation for the \meta{key} or the dictionary entry for the \meta{key} |
| 387 |
doesn't exist. |
| 388 |
\command{ProvideDictTranslation}[\marg{key}\marg{translation}] |
| 389 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 390 |
picks up the language of that file. Only defines the translation and adds |
| 391 |
a corresponding dictionary entry if they don't exist yet. This command is |
| 392 |
used in the dictionaries that a part of \translations. |
| 393 |
\command{DeclareDictTranslation}[\marg{key}\marg{translation}] |
| 394 |
This command is to be used in a dictionary file and picks up the language |
| 395 |
of that file, see \cref{sec:dictionaries} for an example. Defines the |
| 396 |
translation and adds a dictionary entry regardless if they exist or not. |
| 397 |
\command{ProvideDictionaryFor}[\marg{lang}\marg{name}\oarg{date}] |
| 398 |
Needs to be in a dictionary file. This command tells \translations\ that |
| 399 |
the file indeed is a dictionary and also sets the language for the |
| 400 |
dictionary which is used by \cs{DeclareDictTranslation}. |
| 401 |
\expandable\command{PrintDictionaryFor}% |
| 402 |
[\marg{lang}\marg{name}\marg{pre}\marg{mid}\marg{post}] |
| 403 |
\sinceversion{1.0}Prints all entries of dictionary \meta{name} in |
| 404 |
language \meta{lang} in the order the entries have been declared. For |
| 405 |
every entry the code\par |
| 406 |
\meta{pre}\meta{key}\meta{mid}\meta{translation}\meta{post}\par |
| 407 |
is printed. The dictionary must have been loaded of course. There is |
| 408 |
probably only a very limited number of use cases for this command. (It |
| 409 |
was for example used to print \cref{tab:dict}.) |
| 410 |
\expandable\command{baselanguage}[\marg{lang}] |
| 411 |
\changedversion{1.2a}Returns the (internal) base name of the given language, |
| 412 |
language alias or language dialect. For a dialect this expands to the |
| 413 |
name of language it is a dialect of. For a base language (see |
| 414 |
section~\ref{ssec:languages:base}) this usually simply is the lowercase |
| 415 |
version of the name.\par |
| 416 |
\verbcode+\baselanguage{English}+ $\Rightarrow$ \code{english}\\ |
| 417 |
\verbcode+\baselanguage{American}+ $\Rightarrow$ \code{english} |
| 418 |
\expandable\command{ifcurrentlanguage}[\marg{lang}\marg{true}\marg{false}] |
| 419 |
\sinceversion{1.2}Places \meta{true} in the input stream if the current |
| 420 |
language is \meta{lang}. Note: a dialect counts as a language of it's own |
| 421 |
here. \cs{ifcurrentlanguage}\Marg{English} will for example be |
| 422 |
\meta{false} if the current \pkg{babel} language is \code{american}. |
| 423 |
\expandable\command{ifcurrentlang}[\marg{lang}] |
| 424 |
\sinceversion{1.9}The same as \cs{ifcurrentlanguage} but uses the |
| 425 |
\dots\cs{else}\dots\cs*{fi} syntax. |
| 426 |
\expandable\command{ifcurrentbaselanguage}[\marg{lang}\marg{true}\marg{false}] |
| 427 |
\sinceversion{1.2}Places \meta{true} in the input stream if the current |
| 428 |
language is \meta{lang}. Note: a dialect does not count as a language of |
| 429 |
it's own here. If the current \pkg{babel} language is \code{american} |
| 430 |
then \cs{ifcurrentbaselanguage}\Marg{English} will be \meta{true}. |
| 431 |
\expandable\command{ifcurrentbaselang}[\marg{lang}] |
| 432 |
\sinceversion{1.9}The same as \cs{ifcurrentbaselanguage} but uses the |
| 433 |
\dots\cs{else}\dots\cs*{fi} syntax. |
| 434 |
\end{commands} |
| 435 |
|
| 436 |
\subsection{A Small Example} |
| 437 |
This section demonstrates with two short examples how the macros are used. |
| 438 |
The first example covers the basics: declaring of translations and then |
| 439 |
retrieving and typesetting them. |
| 440 |
|
| 441 |
\begin{example} |
| 442 |
% in the preamble: |
| 443 |
% \DeclareTranslation{English}{Kueche}{kitchen} |
| 444 |
% \DeclareTranslation{German}{Kueche}{K\"uche} |
| 445 |
% \DeclareTranslation{Spanish}{Kueche}{cocina} |
| 446 |
% \DeclareTranslation{French}{Kueche}{cuisine} |
| 447 |
|
| 448 |
\GetTranslation{Kueche} |
| 449 |
\SaveTranslation\kitchen{Kueche} |
| 450 |
\SaveTranslationFor\cuisine{french}{Kueche} |
| 451 |
|
| 452 |
\selectlanguage{ngerman} |
| 453 |
\GetTranslation{Kueche} \kitchen\ \GetTranslationFor{spanish}{Kueche} |
| 454 |
\cuisine |
| 455 |
|
| 456 |
\IfTranslation{German}{Kueche}{true}{false} \par |
| 457 |
\IfTranslation{Danish}{Kueche}{true}{false} |
| 458 |
\end{example} |
| 459 |
|
| 460 |
The next example demonstrates the use of dialects and how they fall back to |
| 461 |
the translation for the main language if no extra translation was declared: |
| 462 |
|
| 463 |
\begin{example} |
| 464 |
% in the preamble: |
| 465 |
% \DeclareTranslation{English}{farbe}{color} |
| 466 |
% \DeclareTranslation{British}{farbe}{colour} |
| 467 |
|
| 468 |
\GetTranslationFor{English}{farbe} |
| 469 |
\GetTranslationFor{British}{farbe} |
| 470 |
\GetTranslationFor{American}{farbe} |
| 471 |
\end{example} |
| 472 |
|
| 473 |
\subsection{Usage in Packages} |
| 474 |
\subsubsection{Basic Structure} |
| 475 |
A typical usage in a package would look as follows: |
| 476 |
\begin{sourcecode} |
| 477 |
\RequirePackage{translations} |
| 478 |
\DeclareTranslationFallback{mypackage-title}{Nice Title} |
| 479 |
\DeclareTranslation{English}{mypackage-title}{Nice Title} |
| 480 |
\DeclareTranslation{French}{mypackage-title}{Beau Titre} |
| 481 |
\DeclareTranslation{German}{mypackage-title}{Sch\"{o}ner Titel} |
| 482 |
... |
| 483 |
\newcommand*\mypackage@title{\GetTranslation{mypackage-title}} |
| 484 |
\end{sourcecode} |
| 485 |
|
| 486 |
That is, a package defines some unique key for an expression and at least |
| 487 |
defines a fallback translation. Additionally translations for as many |
| 488 |
languages as the author wants are defined. A user then may add |
| 489 |
\cs{DeclareTranslation}\marg{language}\marg{translation} if they find their |
| 490 |
translation missing. |
| 491 |
|
| 492 |
\subsubsection{The `fallback' language} |
| 493 |
If a user has neither loaded \pkg{babel} nor \pkg{polyglossia} \translations\ |
| 494 |
will use English as language and translate to English if the translation was |
| 495 |
provided. If the user \emph{has} loaded one of the language packages but has |
| 496 |
chosen a language for which no translation is defined the language `fallback' |
| 497 |
will be used, \ie, the translation provided with |
| 498 |
\cs{DeclareTranslationFallback}. If no fallback translation is provided |
| 499 |
either, the translation will expand to the literal string. |
| 500 |
|
| 501 |
The following three examples should make this concept clear: |
| 502 |
|
| 503 |
\begin{example}[compile] |
| 504 |
\documentclass[margin=5mm]{standalone} |
| 505 |
\usepackage{translations} |
| 506 |
\DeclareTranslation{German}{foo-literal}{foo-german} |
| 507 |
\begin{document} |
| 508 |
\GetTranslation{foo-literal} % foo-literal |
| 509 |
\end{document} |
| 510 |
\end{example} |
| 511 |
|
| 512 |
\begin{example}[compile] |
| 513 |
\documentclass[margin=5mm]{standalone} |
| 514 |
\usepackage{translations} |
| 515 |
\DeclareTranslationFallback{foo-literal}{foo} |
| 516 |
\DeclareTranslation{German}{foo-literal}{foo-german} |
| 517 |
\begin{document} |
| 518 |
\GetTranslation{foo-literal} % foo |
| 519 |
\end{document} |
| 520 |
\end{example} |
| 521 |
|
| 522 |
\begin{example}[compile] |
| 523 |
\documentclass[margin=5mm]{standalone} |
| 524 |
\usepackage[ngerman]{babel} |
| 525 |
\usepackage{translations} |
| 526 |
\DeclareTranslationFallback{foo-literal}{foo} |
| 527 |
\DeclareTranslation{German}{foo-literal}{foo-german} |
| 528 |
\begin{document} |
| 529 |
\GetTranslation{foo-literal} % foo-german |
| 530 |
\end{document} |
| 531 |
\end{example} |
| 532 |
|
| 533 |
\subsection{Dictionaries}\label{sec:dictionaries} |
| 534 |
\subsubsection{Background} |
| 535 |
\translations\ provides the means to write dictionary files that can be loaded |
| 536 |
by packages or in a document. Dictionaries can be loaded for the currently |
| 537 |
active language with \cs{LoadDictionary} or for a specific language with |
| 538 |
\cs{LoadDictionaryFor}. |
| 539 |
|
| 540 |
\begin{commands} |
| 541 |
\command{LoadDictionary}[\marg{name}] |
| 542 |
Loads a file named \code{\meta{name}-\meta{lang}.trsl} where \meta{lang} |
| 543 |
corresponds to the lowercase name of the current language or base language |
| 544 |
as defined with \cs{DeclareLanguage}. This file should contain the |
| 545 |
translations for the specified language. This means if \meta{lang} is a |
| 546 |
dialect and a dictionary exists the dictionary is used. If it doesn't |
| 547 |
exist but there is a dictionary for the base language that one is used. |
| 548 |
\command{LoadDictionaryFor}[\marg{lang}\marg{name}] |
| 549 |
Loads a file named \code{\meta{name}-\meta{lang}.trsl} where \meta{lang} |
| 550 |
corresponds to the lowercase name of the current language or base language |
| 551 |
as defined with \cs{DeclareLanguage}. This file should contain the |
| 552 |
translations for the specified language. This means if \meta{lang} is a |
| 553 |
dialect and a dictionary exists the dictionary is used. If it doesn't |
| 554 |
exist but there is a dictionary for the base language that one is used. |
| 555 |
\command{LoadDictionaryForDialect}[\marg{lang}\marg{name}] |
| 556 |
\sinceversion{1.3}Loads a file named \code{\meta{name}-\meta{lang}.trsl} |
| 557 |
where \meta{lang} corresponds to the lowercase name of the current |
| 558 |
language as defined with \cs{DeclareLanguage}. This file should contain |
| 559 |
the translations for the specified language. This command \emph{does not |
| 560 |
look} for a base language dictionary. |
| 561 |
\end{commands} |
| 562 |
|
| 563 |
A package could provide dictionary files for its language dependent settings |
| 564 |
and include the needed one at begin document. The basics for creating a |
| 565 |
dictionary file are explained in section~\ref{sec:own-dictionaries}. |
| 566 |
|
| 567 |
\translations\ already provides a few basic dictionary files. If the main |
| 568 |
document language fits to one of the provided files the corresponding basic |
| 569 |
dictionary is loaded at begin document by \translations, see |
| 570 |
section~\ref{sec:transl-basic-dict} for more on this. |
| 571 |
|
| 572 |
\subsubsection{Own Dictionaries}\label{sec:own-dictionaries} |
| 573 |
A typical dictionary file should look as follows: |
| 574 |
\begin{sourcecode} |
| 575 |
% this is file housing-german.trsl |
| 576 |
\ProvideDictionaryFor{German}{housing}[<version info>] |
| 577 |
\ProvideDictTranslation{kitchen (housing)}{K\"uche} |
| 578 |
\ProvideDictTranslation{bathroom (housing)}{Bad} |
| 579 |
\ProvideDictTranslation{living room (housing)}{Wohnzimmer} |
| 580 |
\ProvideDictTranslation{bedroom (housing)}{Schlafzimmer} |
| 581 |
... |
| 582 |
\endinput |
| 583 |
\end{sourcecode} |
| 584 |
|
| 585 |
The usage is similar to the one in a package: unique keys are given |
| 586 |
translations, this time for the language the dictionary file is declared for |
| 587 |
only. Translations can be declared by one of the following commands: |
| 588 |
\begin{commands} |
| 589 |
\command{NewDictTranslation}[\marg{key}\marg{translation}] |
| 590 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 591 |
picks up the language of that file. Issues an error if either the |
| 592 |
translation for the \meta{key} or the dictionary entry for the \meta{key} |
| 593 |
already exists. |
| 594 |
\command{RenewDictTranslation}[\marg{key}\marg{translation}] |
| 595 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 596 |
picks up the language of that file. Issues an error if either the |
| 597 |
translation for the \meta{key} or the dictionary entry for the \meta{key} |
| 598 |
doesn't exist. |
| 599 |
\command{ProvideDictTranslation}[\marg{key}\marg{translation}] |
| 600 |
\sinceversion{0.10}This command is to be used in a dictionary file and |
| 601 |
picks up the language of that file. Only defines the translation and adds |
| 602 |
a corresponding dictionary entry if they don't exist yet. This command is |
| 603 |
used in the dictionaries that a part of \translations. |
| 604 |
\command{DeclareDictTranslation}[\marg{key}\marg{translation}] |
| 605 |
This command is to be used in a dictionary file and picks up the language |
| 606 |
of that file, see \cref{sec:dictionaries} for an example. Defines the |
| 607 |
translation and adds a dictionary entry regardless if they exist or not. |
| 608 |
\end{commands} |
| 609 |
|
| 610 |
Every dictionary file \emph{must} contain the declaration |
| 611 |
\cs{ProvideDictionaryFor}: |
| 612 |
\begin{commands} |
| 613 |
\command{ProvideDictionaryFor}[\marg{lang}\marg{name}\oarg{date}] |
| 614 |
Needs to be in a dictionary file. This command tells \translations\ that |
| 615 |
the file indeed is a dictionary and also sets the language for the |
| 616 |
dictionary which is used by \cs{NewDictTranslation} or similar commands. |
| 617 |
\end{commands} |
| 618 |
|
| 619 |
\subsubsection{\translations' Basic Dictionaries}\label{sec:transl-basic-dict} |
| 620 |
\translations\ already provides a basic dictionary for the languages |
| 621 |
\begin{itemize} |
| 622 |
\item \sinceversion{1.9}Brazilian, |
| 623 |
\item \sinceversion{1.5}Catalan, |
| 624 |
\item English, |
| 625 |
\item \sinceversion{1.5}Dutch, |
| 626 |
\item French, |
| 627 |
\item German, |
| 628 |
\item \sinceversion{1.12}Polish, and |
| 629 |
\item Spanish. |
| 630 |
\end{itemize} |
| 631 |
The corresponding dictionary\footnote{Or dictionaries if more than one of |
| 632 |
these languages are loaded in a document. This works since v0.18.} is loaded |
| 633 |
automatically if the document language is one of these languages. |
| 634 |
|
| 635 |
\emph{If you'd like to contribute and add the basic dictionary in your |
| 636 |
language this is more than welcome and highly appreciated!} The easiest way |
| 637 |
to do this would be to copy one of the existing files |
| 638 |
\code{translations-basic-dictionary-\meta{lang}.trsl} and modify the file |
| 639 |
accordingly. You can then send me the file via email and I'll add it to |
| 640 |
\translations. |
| 641 |
|
| 642 |
\Cref{tab:dict} lists all words provided by the basic dictionary for German. |
| 643 |
|
| 644 |
\begin{longtable}{ll} |
| 645 |
\caption{All entries of \translations' basic dictionary in German.\label{tab:dict}} \\ |
| 646 |
\toprule |
| 647 |
\rmfamily\bfseries key & \bfseries translation \\ |
| 648 |
\midrule |
| 649 |
\endfirsthead |
| 650 |
\toprule |
| 651 |
\rmfamily\bfseries key & \bfseries translation \\ |
| 652 |
\midrule |
| 653 |
\endhead |
| 654 |
\bottomrule |
| 655 |
\endlastfoot |
| 656 |
\midrule |
| 657 |
& \hfill\emph{continues} \\ |
| 658 |
\endfoot |
| 659 |
\PrintDictionaryFor{German}{translations-basic-dictionary}{\ttfamily}{&}{\\} |
| 660 |
\end{longtable} |
| 661 |
|
| 662 |
|
| 663 |
\section{Defined Languages}\label{sec:languages} |
| 664 |
\subsection{Base Languages}\label{ssec:languages:base} |
| 665 |
Quite a number of languages already are defined, either directly or via an |
| 666 |
alias. So, before you define a language you should take a look at the tables |
| 667 |
below if the language doesn't already exist. \Cref{tab:languages} lists all |
| 668 |
base languages, ``fallback'' being a dummy language used for fallback |
| 669 |
translations. \Cref{tab:languages,tab:dialects,tab:aliases} list \emph{all} |
| 670 |
language names known to \translations. However, they're not sorted |
| 671 |
alphabetically but listed in the order they have been defined. I tried to |
| 672 |
make the definitions in an alphabetical order but sometimes rather grouped |
| 673 |
related language names together. |
| 674 |
|
| 675 |
If you miss a language or recognize a language that has falsely been declared |
| 676 |
as an alias but should rather be a dialect or base language itself (or any |
| 677 |
variation of this theme) please let me know, preferably with a short |
| 678 |
explanation what's wrong and why. |
| 679 |
|
| 680 |
\newcounter{column} |
| 681 |
\def\seplang{% |
| 682 |
\stepcounter{column}% |
| 683 |
\ifnumless{\value{column}}{5} |
| 684 |
{&} |
| 685 |
{\\\setcounter{column}{0}}% |
| 686 |
} |
| 687 |
\def\do#1{#1\seplang} |
| 688 |
\makeatletter |
| 689 |
\begin{longtable}{lllll} |
| 690 |
\caption{Base languages defined by \translations, from left to right in |
| 691 |
the order of definition.\label{tab:languages}} \\ |
| 692 |
\toprule |
| 693 |
\endfirsthead |
| 694 |
\toprule |
| 695 |
\endhead |
| 696 |
\bottomrule |
| 697 |
\endlastfoot |
| 698 |
\midrule |
| 699 |
&&&& \hfill\emph{continues} \\ |
| 700 |
\endfoot |
| 701 |
\dolistloop\@trnslt@languages |
| 702 |
\end{longtable} |
| 703 |
\makeatother |
| 704 |
|
| 705 |
\subsection{Language Dialects}\label{ssec:languages:dialects} |
| 706 |
\translations\ also defines a few dialects of thebase languages. They are |
| 707 |
listed in \cref{tab:dialects}. The decision what is a dialect and what is an |
| 708 |
alias is not always clear. I am no linguist so I looked up information |
| 709 |
available on the internet. A language that was described as |
| 710 |
\enquote{standardized register} was always defined as a dialect. For some |
| 711 |
other languages it seemed to make sense, such as British or Austrian. The |
| 712 |
decisions are open for debate. |
| 713 |
|
| 714 |
\setcounter{column}{0} |
| 715 |
\gdef\seplang{% |
| 716 |
\ifnumgreater{\value{column}}{3} |
| 717 |
{\setcounter{column}{1}} |
| 718 |
{\stepcounter{column}}% |
| 719 |
\ifnumless{\value{column}}{4} |
| 720 |
{&} |
| 721 |
{\\}% |
| 722 |
} |
| 723 |
\def\aliases#1#2{#1\seplang #2\seplang} |
| 724 |
\def\do#1{\aliases#1} |
| 725 |
\makeatletter |
| 726 |
\begin{longtable}{ll@{\hspace*{4em}}ll} |
| 727 |
\caption{All dialects defined by \translations, from left to right in the |
| 728 |
order of definition.\label{tab:dialects}}\\ |
| 729 |
\toprule |
| 730 |
\bfseries dialect & \bfseries language & |
| 731 |
\bfseries dialect & \bfseries language \\ |
| 732 |
\midrule |
| 733 |
\endfirsthead |
| 734 |
\toprule |
| 735 |
\bfseries dialect & \bfseries language & |
| 736 |
\bfseries dialect & \bfseries language \\ |
| 737 |
\midrule |
| 738 |
\endhead |
| 739 |
\bottomrule |
| 740 |
\endlastfoot |
| 741 |
\midrule |
| 742 |
&&& \hfill\emph{continues} \\ |
| 743 |
\endfoot |
| 744 |
\dolistloop\@trnslt@dialects@pair |
| 745 |
\end{longtable} |
| 746 |
\makeatother |
| 747 |
|
| 748 |
\subsection{Language Aliases}\label{ssec:languages:aliases} |
| 749 |
To most of the base languages and dialects at least one alias exists, the |
| 750 |
uppercase variant. This is due to the fact that it is common to write |
| 751 |
language names uppercased. For a number of languages aliases were defined in |
| 752 |
order to match \pkg{babel}'s or \pkg{polyglossia}'s names for the |
| 753 |
languages. Others are defined because there apparently exist more than one |
| 754 |
name for the same language. The decisions are not consistent. For example it |
| 755 |
could be argued that \enquote{deutsch} is an alias of \enquote{German}. I am |
| 756 |
open to suggestions and improvements. All defined aliases are listed in |
| 757 |
\cref{tab:aliases}. |
| 758 |
|
| 759 |
\setcounter{column}{0} |
| 760 |
\makeatletter |
| 761 |
\begin{longtable}{ll@{\hspace*{4em}}ll} |
| 762 |
\caption{All language aliases defined by \translations, from left to right |
| 763 |
in the order of definition.\label{tab:aliases}}\\ |
| 764 |
\toprule |
| 765 |
\bfseries alias & \bfseries language & |
| 766 |
\bfseries alias & \bfseries language \\ |
| 767 |
\midrule |
| 768 |
\endfirsthead |
| 769 |
\toprule |
| 770 |
\bfseries alias & \bfseries language & |
| 771 |
\bfseries alias & \bfseries language \\ |
| 772 |
\midrule |
| 773 |
\endhead |
| 774 |
\bottomrule |
| 775 |
\endlastfoot |
| 776 |
\midrule |
| 777 |
&&& \hfill\emph{continues} \\ |
| 778 |
\endfoot |
| 779 |
\dolistloop\@trnslt@aliases@pair |
| 780 |
\end{longtable} |
| 781 |
\makeatother |
| 782 |
|
| 783 |
These languages \emph{should} cover all languages which are currently covered |
| 784 |
by \pkg{babel} and \pkg{polyglossia} but very likely this is not the |
| 785 |
case. Should you miss a language please send me an email so I can add it to |
| 786 |
\translations. |
| 787 |
|
| 788 |
% \section{Implementation} |
| 789 |
% \lstinputlisting[style=cnltx]{translations.sty} |
| 790 |
|
| 791 |
\printbibliography |
| 792 |
|
| 793 |
\end{document} |