TransWikia.com

How to add and use Arabic dictionary translation for theorem, example,

TeX - LaTeX Asked on March 14, 2021

With beamer babel translate strings like Figure, Table, Table of Contents, …. more strings like theorem, example, definition, ….. are translated with translator package for some languages. but Arabic language isn’t supported with translator. how can I add translation of those strings in Arabic?

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

todaypar 
contentsnamepar 
figurenamepar

hrulefill

% strings non translated

%
sectionnamepar 
begin{theorem}
end{theorem}

begin{example}
end{example}

begin{corollary}
end{corollary}

begin{definition}
end{definition}

end{frame}
end{document}

enter image description here

My aim is to use translator package, I have created Arabic dictionaries

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 

For example contents of translator-numbers-dictionary-Arabic.dict file

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.}

Then I have inserted this line to translator.sty to add Arabic option

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

And I try with this example which does not give the desired result

% 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}

enter image description here

Update

@Davislor I still face some issues, for just one language Arabic I need to insert languagepath{Arabic} but with two languages the last code cause the translation for second language to appears also in 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}

Without languagepath{Arabic}

enter image description here

With languagepath{Arabic}

enter image description here

One Answer

If you have already created the dictionaries translator-theorem-dictionary-Arabic.dict, etc., in some directory your TeX engine searches, you need to add the line

uselanguage{Arabic}

to your preamble, and translator, which beamer loads, will use them. If you want to follow the naming convention of the translator package, but also have translator select Arabic when the current languagename is arabic, also add the command

languagealias{arabic}{Arabic}

I used your numbers dictionary and the following dummy translate-theorem-dictionary-Arabic.dict. I did not even attempt to translate Arabic sttings, since you say you’ve done that already, but put in placeholders to verify that translator is using the right dictionary.

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}

This, plus the example translator-numbers-dictionary.Arabic.dict that you provided, is enough to compile the following 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}

todaypar 
figurenamepar
contentsnamepar

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{upshapetranslate{one}}) en castellano.
end{theorem}
end{spanish}

end{frame}
end{document}

Amiri/Libertinus font sample

You seem to want to modify the translator package itself to run the two necessary commands if you give it the [arabic] option. For the time being, you would be stuck using PassOptionsToPackage{arabic}{translator} before documentclass{beamer}, since for the moment you cannot pass [arabic] to the document class without passing it to babel, which loads an obsolete 8-bit .ldf file and breaks. You could work around this by supporting usepackage[Arabic]{translator}.

I note in passing that the basic design of translator is inadequate for translating even phrases such as “the first theorem.” It assumes you can translate English into other languages simply by word substitution. That breaks even for Spanish grammar, where translate{first} would give you “primero” and there is no way to generate ”primera,” “primer,” “segunda,” etc. It’s even more unsuitable for German, where the correct translation of “first” in context might be “erste”, “erster”, “erstem”, “ersten”, or “erstes”.

Original Answer

You can define new theorem environments with amsthm (and its Beamer extensions), similar to the ones Beamer provides for German.

% 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}

todaypar 
figurenamepar
contentsnamepar

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}

There isn’t a sectionname in the standard classes, and Beamer doesn’t display one. However, you could provide a translation of a caption Babel supports, such asarabicchaptername or chaptername, or redefine the header format.

If you want to write a new package, you probably want to take advantage of translator dictionaries.

Correct answer by Davislor on March 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP