5

Suppose I'm preparing LaTeX package to give the abstraction of admonition boxes (warning, error, tip, note, fyi, ...).

I'd like to have theses strings internationalized. I wouldn't appreciate the following solutions:

  • "generic" box, let the user give the title and icon.
  • add an option to your sty file so that the user can configure the language
  • make many sty files suffixed by the language code

The "babel" package is capable of defining some i18n strings (Table of Contents, Table des matières, ...).

Is it possible to integrate the strings used in my package with a i18n system?

Sorry but searching for latex, i18n, babel, interface, integration or whatever don't give me useful results (most people have doubts on how to get babel to work in their documents).

Thanks in advance.

lockstep
  • 250,273
LRMAAX
  • 213

3 Answers3

5

You could try the »translator« package that is shipped with the beamer class. It is described in Section 25 of the class user guide.

3

Maybe a late answer, but babelallows you to have separate .cfg files with the name of the language (UKenglish.cfg, norsk.cfg, swedish.cfg, etc.) and use the babel macro addto{<caption_name>}.

For example, I have a file UKenglish.cfg in my texmf-local directory, with the following definition used by my own macros:

%% UKenglish.cfg
%% Local config file UKenglish.cfg used by babel

%% to add an entry to english
\addto{\captionsUKenglish}{%
    \def\Companynumbername{company number}%
    \def\shVersion{Version}%
    \def\shversion{version}%
}

And I have a corresponding norsk.cfg to cover the two languages I mostly use.

Sveinung
  • 20,355
2

Maybe a much later answer, but I've just run into the same problem, and if you want to translate something inside of a LaTeX package, providing .cfg files is not a good solution if you want the user to be able to provide additional .cfg files themselves. My solution was to use babel's \languagename with deferred evaluation and define adequately named macros:

%% Suppose \lastpage is set somewhere. We define our translation strings:
\def\pagenameofenglish{Page \thepage\ of \lastpage}
\def\pagenameofgerman{Seite \thepage\ von \lastpage}
\def\pagenameofdutch{Pagina \thepage\ van \lastpage}
%% also remember to define all the language aliases...
\let\pagenameofUKenglish\pagenameofenglish
\let\pagenameofamerican\pagenameofenglish
%% ... and so on

%% We define english as our default language.
%% If babel is loaded with a new language, this gets overwritten.
\ifx\languagename\undefined\def\languagename{english}\fi

%% Use the translated string
%% The \csname expands everything what is given and builds a command from it,
%% e.g., if \languagename is "german", this gets expanded to \pagenameofgerman:
\def\pagenameof{\csname pagenameof\languagename\endcsname}

%% You can now use that e.g. in your fancyheader setup:
\cfoot{\pagenameof}
rohieb
  • 21