我正忙于一个新的文档类,并尝试将一些内容国际化。我尝试过使用translator
Beamer。这是一个好的策略吗?下面显示的代码可以改进吗?还有其他选项可以执行这样的任务吗?
%% 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}
答案1
另一种方法是使用scrbase
KOMA-Script 中的包。似乎缺少关于此包的章节scrguien.pdf
。下面是一个例子:
\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}
还有命令\newcaptionname
和\renewcaptionname
。
顺便说一句:我曾经\expandafter\MakeUppercase
改变过术语首字母的大小写。因此,像“error”这样的术语只需要出现一次,而不是两次。这只是一个小技巧,但通常很有用。