![根据巴别语言翻译单词](https://linux22.com/image/269405/%E6%A0%B9%E6%8D%AE%E5%B7%B4%E5%88%AB%E8%AF%AD%E8%A8%80%E7%BF%BB%E8%AF%91%E5%8D%95%E8%AF%8D.png)
我有一个要用法语或英语的模板,babel 中是否有一个名称来定义“第 x 页,共 yy 页”的“of”,然后我想将其自动翻译为“第 x 页,共 y 页”
如果没有,有没有办法根据在 babel 中选择的语言设置名称。
答案1
我想到两个包:(translator
来自beamer
捆绑)和translations
我将为两者分别展示一个例子,输出如下:
第一页:
第二页:
以下是translations
版本:
\documentclass{article}
\usepackage[ngerman,french,english]{babel}
\usepackage[lastpage,user]{zref}
\usepackage{translations}
% used when a language is used for which no translation exists:
\DeclareTranslationFallback{page-of-pages}
{page~\thepage\ of~\zpageref{LastPage}}
% translations:
\DeclareTranslation{German}{page-of-pages}
{Seite~\thepage\ von~\zpageref{LastPage}}
\DeclareTranslation{French}{page-of-pages}
{page~\thepage\ sur~\zpageref{LastPage}}
\DeclareTranslation{English}{page-of-pages}
{page~\thepage\ of~\zpageref{LastPage}}
\begin{document}
\selectlanguage{ngerman}
\GetTranslation{page-of-pages}
\selectlanguage{french}
\GetTranslation{page-of-pages}
\selectlanguage{english}
\GetTranslation{page-of-pages}
\newpage
\selectlanguage{ngerman}
\GetTranslation{page-of-pages}
\selectlanguage{french}
\GetTranslation{page-of-pages}
\selectlanguage{english}
\GetTranslation{page-of-pages}
\end{document}
这是与 类似的版本translator
。请注意,它需要通过提供选项来了解语言,这里通过将它们声明为类选项来完成:
\documentclass[ngerman,french,english]{article}
\usepackage{babel}
\usepackage[lastpage,user]{zref}
\usepackage{translator}
\newtranslation[to=German]{page-of-pages}
{Seite~\thepage\ von~\zpageref{LastPage}}
\newtranslation[to=French]{page-of-pages}
{page~\thepage\ sur~\zpageref{LastPage}}
\newtranslation[to=English]{page-of-pages}
{page~\thepage\ of~\zpageref{LastPage}}
\begin{document}
\selectlanguage{ngerman}
\translate{page-of-pages}
\selectlanguage{french}
\translate{page-of-pages}
\selectlanguage{english}
\translate{page-of-pages}
\newpage
\selectlanguage{ngerman}
\translate{page-of-pages}
\selectlanguage{french}
\translate{page-of-pages}
\selectlanguage{english}
\translate{page-of-pages}
\end{document}
答案2
对于有限的范围,可以手动完成:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,french]{babel}
\usepackage{lastpage}
\makeatletter
\newcommand{\pageofpages}{%
\@ifundefined{pageof@\languagename}
{page \thepage\ of \pageref{LastPage}} % a default
{\@nameuse{pageof@\languagename}}%
}
% English is already default
% \newcommand{\pageof@english}{page \thepage\ of \pageref{LastPage}}
% French
\newcommand{\pageof@french}{page \thepage\ sur \pageref{LastPage}}
\makeatother
\begin{document}
\pageofpages\newpage
\selectlanguage{english}
\pageofpages\newpage
\pageofpages
\selectlanguage{french}\pageofpages
\end{document}