blob: a52d3708632d52ce634bffd8004fc137a6cc20e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
% ----------------------------------------------------------------------------
% the XSIM package - translations module
%
% eXercise Sheets IMproved
%
% ----------------------------------------------------------------------------
% Clemens Niederberger
% Web: https://github.com/cgnieder/xsim
% E-Mail: contact@mychemistry.eu
% ----------------------------------------------------------------------------
% Copyright 2017 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% ----------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% ----------------------------------------------------------------------------
\XSIMmodule{translations}{language settings for XSIM}
\RequirePackage{translations}
\msg_new:nnn {xsim} {language-not-defined}
{
You~ chose~ the~ language~ `#1'~ which~ is~ not~ defined~ by~ xsim.~
`english'~ is~ used~ instead.~ If~ you~ just~ mistyped~ try~ again!~
Otherwise~ contact~ the~ author~ and~ he'll~ probably~ add~ your~ language.
}
% --------------------------------------------------------------------------
\bool_new:N \l__xsim_language_auto_bool
\bool_set_true:N \l__xsim_language_auto_bool
% this token list will hold the chosen language for xsim; since the
% language is either chosen automatically or by option it is only available at
% begin document
\tl_new:N \l_xsim_language_tl
\tl_set:Nn \l_xsim_language_tl {english}
\tl_new:N \l__xsim_current_language_tl
\tl_const:Nn \c__xsim_keyword_prefix_tl {xsim-keyword-}
% ----------------------------------------------------------------------------
\prop_new:N \g_xsim_translations_prop
% translate the key #1
\cs_new:Npn \xsim_translate:n #1
{
\bool_if:NTF \l__xsim_language_auto_bool
{ \GetTranslation { \c__xsim_keyword_prefix_tl #1 } }
{
\GetTranslationFor
{ \l_xsim_language_tl }
{ \c__xsim_keyword_prefix_tl #1 }
}
}
\AtBeginDocument{
\bool_if:NTF \l__xsim_language_auto_bool
{
\tl_set:Nx \l_xsim_language_tl
{ \@trnslt@language{\@trnslt@current@language} }
}
{
\tl_set_eq:NN
\l_xsim_language_tl
\l__xsim_current_language_tl
}
}
% ----------------------------------------------------------------------------
% #1: keyword
% #2: language
% #3: translation
\cs_new_protected:Npn \__xsim_declare_translation:nw #1#2=#3\q_stop
{
\tl_set:Nx \l__xsim_tmpa_tl { \tl_trim_spaces:n {#2} }
\tl_set:Nx \l__xsim_tmpb_tl { \tl_trim_spaces:n {#3} }
\xsim_declare_translation:VnV
\l__xsim_tmpa_tl
{#1}
\l__xsim_tmpb_tl
}
% #1: language
% #2: keyword
% #3: translation
\cs_new_protected:Npn \xsim_declare_translation:nnn #1#2#3
{
\xsim_verbose:n
{ Declaring~ `#1'~ tranlation~ of~ `#2':~ `#3'. }
\declaretranslation
{#1}
{ \c__xsim_keyword_prefix_tl #2 }
{#3}
\prop_gput:Nnn \g_xsim_translations_prop {#2(#1)} {#3}
}
\cs_generate_variant:Nn \xsim_declare_translation:nnn {V,VnV}
% #1: key
% #2: csv list: { <lang1> = <translation1> , <lang2> = <translation2> }
\cs_new_protected:Npn \xsim_declare_translations:nn #1#2
{
\clist_map_inline:nn {#2}
{ \__xsim_declare_translation:nw {#1} ##1 \q_stop }
}
\cs_new:Npn \__xsim_parse_translate_list_entry:nnn #1#2#3 {}
\cs_new_protected:Npn \__xsim_parse_translate_list_entry:www #1(#2)\q_mark#3\q_stop
{ \__xsim_parse_translate_list_entry:nnn {#1} {#2} {#3} }
\cs_new_protected:Npn \xsim_for_all_translations_do:n #1
{
\cs_set:Npn \__xsim_parse_translate_list_entry:nnn ##1##2##3 {#1}
\prop_map_inline:Nn \g_xsim_translations_prop
{ \__xsim_parse_translate_list_entry:www ##1 \q_mark ##2 \q_stop }
}
% ----------------------------------------------------------------------------
\keys_define:nn {xsim}
{
language .value_required:n = true ,
language .code:n =
\tl_if_eq:nnTF {#1} {auto}
{ \bool_set_true:N \l__xsim_language_auto_bool }
{
\bool_set_false:N \l__xsim_language_auto_bool
\tl_set:Nn \l__xsim_current_language_tl {#1}
} ,
language .initial:n = auto
}
% ----------------------------------------------------------------------------
\tex_endinput:D
|