更新

更新

使用 beamer babel 翻译字符串,如图形、表格、目录等。更多的字符串,如定理、例子、定义等,都可以用translator某些语言的包进行翻译。但不支持阿拉伯语translator。我怎样才能添加这些字符串的阿拉伯语翻译?

% lualatex
\documentclass{beamer}
\usepackage[bidi=basic]{babel}
\babelprovide[import=ar-DZ, main]{arabic}
\babelfont{sf}{Amiri}
\begin{document}
\begin{frame}{Test}

\today\par 
\contentsname\par 
\figurename\par

\hrulefill

% strings non translated

%
\sectionname\par 
\begin{theorem}
\end{theorem}

\begin{example}
\end{example}

\begin{corollary}
\end{corollary}

\begin{definition}
\end{definition}

\end{frame}
\end{document}

在此处输入图片描述

我的目标是使用translator包,我已经创建了阿拉伯语词典

translator-months-dictionary-Arabic.dict
translator-theorem-dictionary-Arabic.dict
translator-numbers-dictionary-Arabic.dict
translator-basic-dictionary-Arabic.dict
translator-bibliography-dictionary-Arabic.dict
translator-environment-dictionary-Arabic.dict 

例如translator-numbers-dictionary-Arabic.dict文件内容

\ProvidesDictionary{translator-numbers-dictionary}{Arabic}

\providetranslation{one}{واحد}
\providetranslation{two}{اثنان}
\providetranslation{three}{ثلاثة}
\providetranslation{four}{أربعة}
\providetranslation{five}{خمسة}
\providetranslation{six}{ستة}
\providetranslation{seven}{سبعة}
\providetranslation{eight}{ثمانية}
\providetranslation{nine}{تسعة}
\providetranslation{ten}{عشرة}
\providetranslation{eleven}{احدى عشرة}
\providetranslation{twelve}{اثنى عشرة}

\providetranslation{One}{واحد}
\providetranslation{Two}{اثنان}
\providetranslation{Three}{ثلاثة}
\providetranslation{Four}{أربعة}
\providetranslation{Five}{خمسة}
\providetranslation{Six}{ستة}
\providetranslation{Seven}{سبعة}
\providetranslation{Eight}{ثمانية}
\providetranslation{Nine}{تسعة}
\providetranslation{Ten}{عشرة}
\providetranslation{Eleven}{احدى عشرة}
\providetranslation{Twelve}{اثنى عشرة}

\providetranslation{first}{الأول}
\providetranslation{second}{الثاني}
\providetranslation{third}{الثالث}
\providetranslation{fourth}{الرابع}
\providetranslation{fifth}{الخامس}
\providetranslation{sixth}{السادس}
\providetranslation{seventh}{السابع}
\providetranslation{eighth}{الثامن}
\providetranslation{ninth}{التاسع}
\providetranslation{tenth}{العاشر}
\providetranslation{eleventh}{الحادي عشر}
\providetranslation{twelfth}{الثاني عشر}

\providetranslation{1st}{1.}
\providetranslation{2nd}{2.}
\providetranslation{3rd}{3.}
\providetranslation{4th}{4.}
\providetranslation{5th}{5.}
\providetranslation{6th}{6.}
\providetranslation{7th}{7.}
\providetranslation{8th}{8.}
\providetranslation{9th}{9.}
\providetranslation{10th}{10.}
\providetranslation{11th}{11.}
\providetranslation{12th}{12.}

然后我插入此行来translator.sty添加阿拉伯语选项

\DeclareOption{arabic}        {\trans@use@and@alias{arabic}    {Arabic}}

我尝试了这个例子,但没有得到预期的结果

% lualatex
\PassOptionsToPackage{arabic}{translator}
\documentclass{beamer}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}

\babelfont{sf}{Amiri}

\begin{document}
\begin{frame}{Test}

\begin{theorem}

\end{theorem}

\translate[to=Arabic]{one}

\end{frame}
\end{document}

在此处输入图片描述

更新

@Davislor 我仍然面临一些问题,对于一种语言,我需要插入阿拉伯语,\languagepath{Arabic}但对于两种语言,最后一段代码会导致第二种语言的翻译也出现在阿拉伯语中

% lualatex
\documentclass[spanish]{beamer}
\usepackage[bidi=basic,nil]{babel}
\babelprovide[import,main]{arabic}

\babelfont{sf}{Amiri}

\uselanguage{Arabic}
%\languagepath{Arabic}

% This way translation for Spanish is ok but there is no
% translation for theorem in Arabic !
% If we incomment \languagepath{Arabic} translation for 
% Arabic is ok but with Spanish translation of therem appears in Arabic !
   
\begin{document}
\begin{frame}{Test}

\begin{theorem}

\end{theorem}

\translate[to=Arabic]{one}

\selectlanguage{spanish}

\begin{theorem}

\end{theorem}

\end{frame}
\end{document}

不含 \languagepath{Arabic}

在此处输入图片描述

使用 \languagepath{Arabic}

在此处输入图片描述

答案1

如果你已经在 TeX 引擎搜索的某​​个目录中创建了字典translator-theorem-dictionary-Arabic.dict等,则需要添加以下行

\uselanguage{Arabic}

到你的序言中,和translatorbeamer加载后,将使用它们。如果你想遵循translator包的命名约定,但也要translator在当前为 时选择阿拉伯语\languagenamearabic还请添加命令

\languagealias{arabic}{Arabic}

我使用了您的数字词典和以下虚拟词典translate-theorem-dictionary-Arabic.dict。我甚至没有尝试翻译阿拉伯语设置,因为您说您已经这样做了,而是放入了占位符来验证是否translator使用了正确的词典。

\ProvidesDictionary{translator-theorem-dictionary}{Arabic}

\providetranslation{Comments}{Comments in Arabic}
\providetranslation{comments}{comments in Arabic}
\providetranslation{Comment}{Comment in Arabic}
\providetranslation{comment}{comment in Arabic}
\providetranslation{Corollaries}{Corollaries in Arabic}
\providetranslation{corollaries}{corollaries in Arabic}
\providetranslation{Corollary}{Corollary in Arabic}
\providetranslation{corollary}{corollary in Arabic}
\providetranslation{Definitions}{Definitions in Arabic}
\providetranslation{definitions}{definitions in Arabic}
\providetranslation{Definition}{Definition in Arabic}
\providetranslation{definition}{definition in Arabic}
\providetranslation{Examples}{Examples in Arabic}
\providetranslation{examples}{examples in Arabic}
\providetranslation{Example}{Example in Arabic}
\providetranslation{example}{example in Arabic}
\providetranslation{Exercises}{Exercises in Arabic}
\providetranslation{exercises}{exercises in Arabic}
\providetranslation{Exercise}{Exercise in Arabic}
\providetranslation{exercise}{exercise in Arabic}
\providetranslation{Facts}{Facts in Arabic}
\providetranslation{facts}{facts in Arabic}
\providetranslation{Fact}{Fact in Arabic}
\providetranslation{fact}{fact in Arabic}
\providetranslation{Key Lemmas}{Key Lemmas in Arabic}
\providetranslation{key lemmas}{key lemmas in Arabic}
\providetranslation{Key Lemma}{Key Lemma in Arabic}
\providetranslation{key lemma}{key lemma in Arabiv}
\providetranslation{Key Observations}{Key Observations in Arabic}
\providetranslation{key observations}{key observations in Arabic}
\providetranslation{Key Observation}{Key Observation in Arabic}
\providetranslation{key observation}{key observation in Arabic}
\providetranslation{Lemmas}{Lemmas in Arabic}
\providetranslation{lemmas}{lemmas in Arabic}
\providetranslation{Lemma}{Lemma in Arabic}
\providetranslation{lemma}{lemma in Arabic}
\providetranslation{Main Theorems}{Main Theorems in Arabic}
\providetranslation{main theorems}{main theorems in Arabic}
\providetranslation{Main Theorem}{Main Theorem in Arabic}
\providetranslation{main theorem}{main theorem in Arabic}
\providetranslation{Observations}{Observations in Arabic}
\providetranslation{observations}{observations in Arabic}
\providetranslation{Observation}{Observation in Arabic}
\providetranslation{observation}{observation in Arabic}
\providetranslation{Problems}{Problems in Arabic}
\providetranslation{problems}{problems in Arabic}
\providetranslation{Problem}{Problem in Arabic}
\providetranslation{problem}{problem in Arabic}
\providetranslation{Proofs}{Proofs in Arabic}
\providetranslation{proofs}{proofs in Arabic}
\providetranslation{Proof}{Proof in Arabic}
\providetranslation{proof}{proof in Arabic}
\providetranslation{Proof Sketch}{Proof Sketch in Arabic}
\providetranslation{Proof sketch}{Proof sketch in Arabic}
\providetranslation{proof sketch}{proof sketch in Arabic}
\providetranslation{Proof Sketches}{Proof Sketches in Arabic}
\providetranslation{Proof sketches}{Proof sketches in Arabic}
\providetranslation{proof sketches}{proof sketches in Arabic}
\providetranslation{Sketch of Proof}{Sketch of Proof in Arabic}
\providetranslation{Sketch of Proofs}{Sketch of Proofs in Arabic}
\providetranslation{Sketch of proof}{Sketch of proof in Arabic}
\providetranslation{Sketch of proofs}{Sketch of proofs in Arabic}
\providetranslation{sketch of proof}{sketch of proof in Arabic}
\providetranslation{sketch of proofs}{sketch of proofs in Arabic}
\providetranslation{Propositions}{Propositions in Arabic}
\providetranslation{propositions}{propositions in Arabic}
\providetranslation{Proposition}{Proposition in Arabic}
\providetranslation{proposition}{proposition in Arabic}
\providetranslation{Remarks}{Remarks in Arabic}
\providetranslation{remarks}{remarks in Arabic}
\providetranslation{Remark}{Remark in Arabic}
\providetranslation{remark}{remark in Arabic}
\providetranslation{Solutions}{Solutions in Arabic}
\providetranslation{solutions}{solutions in Arabic}
\providetranslation{Solution}{Solution in Arabic}
\providetranslation{solution}{solution in Arabic}
\providetranslation{Theorems}{Theorems in Arabic}
\providetranslation{theorems}{theorems in Arabic}
\providetranslation{Theorem}{Theorem in Arabic}
\providetranslation{theorem}{theorem in Arabic}

这加上您提供的示例translator-numbers-dictionary.Arabic.dict足以编译以下 MWE:

% lualatex
\tracinglostchars=2 % Warn if using a character not in the current font.
\documentclass[professionalfonts,unicode,spanish,english]{beamer}
\usepackage[bidi=basic,layout=sectioning,nil]{babel}
\usepackage{unicode-math}

%% You seem to want these commands activated by passing translator the
%% [arabic] or [Arabic] options.  You can give the latter to `\documentclass`
%% without activating an obsolete, incompatible .ini file in babel.
\uselanguage{Arabic}
\languagealias{arabic}{Arabic}

\babelprovide[import=ar-DZ, main]{arabic}
\newenvironment{spanish}%
  {\begin{otherlanguage}{spanish}}%
  {\end{otherlanguage}}
\babeltags{Arabic=arabic}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }
\babelfont{rm}[Ligatures={Common,Discretionary},Scale=1.0]{Libertinus Serif}
\babelfont{sf}[Ligatures={Common,Discretionary}]{Libertinus Sans}
\babelfont{tt}{Libertinus Mono}
\babelfont[arabic]{rm}[Scale=1.0]{Amiri}
\babelfont[arabic]{sf}[Language=Default]{Noto Sans Arabic}
\babelfont[arabic]{tt}{ALM Fixed}
\setmathfont{Libertinus Math}

\usefonttheme{serif}

\begin{document}
\begin{frame}{Test}

\today\par 
\figurename\par
\contentsname\par

\hrulefill

% strings non translated
 
\tableofcontents
\section{A Section}
 
\begin{theorem}
\end{theorem}

\begin{example}
\end{example}

\begin{corollary}
\end{corollary}

\begin{definition}
\end{definition}

\begin{spanish}
\begin{theorem}
El primer teorema (\textArabic{\upshape\translate{one}}) en castellano.
\end{theorem}
\end{spanish}

\end{frame}
\end{document}

Amiri/Libertinus 字体样本

translator如果给它提供选项,您似乎想要修改包本身以运行两个必要的命令[arabic]。目前,您将只能使用\PassOptionsToPackage{arabic}{translator}before \documentclass{beamer},因为目前您无法[arabic]在不将其传递给 的情况下将其传递给文档类babel,这会加载过时的 8 位.ldf文件并中断。您可以通过支持 来解决这个问题\usepackage[Arabic]{translator}

我顺便指出,的基本设计translator甚至不足以翻译诸如“第一定理”之类的短语。它假设您可以通过替换单词将英语翻译成其他语言。这对于西班牙语语法来说也是如此,西班牙语\translate{first}会给出“primero”,而没有办法生成“primera”、“primer”、“segunda”等。它甚至更不适合德语,因为在德语中,“first”在上下文中的正确翻译可能是“erste”、“erster”、“erstem”、“ersten”或“erstes”。

原始答案

您可以使用amsthm(及其 Beamer 扩展) 定义新的定理环境,类似于 Beamer 为德语提供的环境。

% lualatex
\documentclass[professionalfonts]{beamer}
\usepackage[bidi=basic,layout=sectioning,nil]{babel}
\usepackage{unicode-math}
\babelprovide[import=ar-DZ, main]{arabic}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }
\babelfont{rm}[Scale=1.0]{Amiri}
\babelfont{sf}[Language=Default]{Noto Sans Arabic}
\babelfont{tt}{ALM Fixed}
\setmathfont{Libertinus Math}

\usefonttheme{serif}

\babeltags{ar=arabic}

\theoremstyle{plain}
\newtheorem{arthm}{\textar{Translation of Theorem}}[section]
\newtheorem*{arcor}{\textar{Translation of Corollary}}
\theoremstyle{definition}
\newtheorem{ardefn}{\textar{Translation of Definition}}[section]
\newtheorem{arexmpl}{\textar{Translation of Example}}

\begin{document}
\begin{frame}{Test}

\today\par 
\figurename\par
\contentsname\par

\hrulefill

% strings non translated
 
\tableofcontents
\section{A Section}
 
\begin{arthm}
\end{arthm}

\begin{arexmpl}
\end{arexmpl}

\begin{arcor}
\end{arcor}

\begin{ardefn}
\end{ardefn}

\end{frame}
\end{document}

标准类中没有\sectionname,Beamer 也不显示 。但是,您可以提供 Babel 支持的字幕翻译,例如\arabicchaptername\chaptername,或者重新定义标题格式。

如果您想编写一个新包,您可能想利用translator字典。

相关内容