summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/translations/translations.sty
blob: 789f5eb19d61c6e6c6ac45296627fb7aa622f468 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
% --------------------------------------------------------------------------
% the TRANSLATIONS package
% 
%   internationalization of LaTeX2e packages
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% Web:    http://www.mychemistry.eu/forums/forum/translations
% E-Mail: contact@mychemistry.eu
% --------------------------------------------------------------------------
% Copyright 2012-2015 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.
% --------------------------------------------------------------------------
\def\@trnslt@date{2015/08/29}
\def\@trnslt@version{v1.2c}
\def\@trnslt@info{internationalization of LaTeX2e packages}

\ProvidesPackage{translations}[%
  \@trnslt@date\space
  \@trnslt@version\space
  \@trnslt@info\space (CN)]
\RequirePackage{cnltx-base,scrlfile}

% --------------------------------------------------------------------------
% message handling
% generic help message:
\def\@trnslt@error@message{%
  For details have a look at the `translations' manual.%
}

% create message macros:
\cnltx@create@generic@message{@trnslt}{translations}{Error}{\@trnslt@error@message}
\cnltx@create@generic@message{@trnslt}{translations}{Warning}{}
\cnltx@create@generic@message{@trnslt}{translations}{WarningNoLine}{}
\cnltx@create@generic@message{@trnslt}{translations}{Info}{}

% specific errors:
\newrobustcmd*\@trnslt@err@unknown@lang[1]{\@trnslt@error{Unknown language `#1'}}
\newrobustcmd*\@trnslt@warn@unknown@lang[1]{\@trnslt@warning{Unknown language `#1'}}
\newrobustcmd*\@trnslt@err@already@defined[2]{%
  \@trnslt@error{The #2 translation for `#1' is already defined.}%
}
\newrobustcmd*\@trnslt@err@not@defined[2]{%
  \@trnslt@error{%
    The \@trnslt@language{#2} translation for `#1' is not defined yet.%
  }%
}
\newrobustcmd*\@trnslt@err@dict@already@defined[2]{%
  \@trnslt@error{The #2 dictionary entry for `#1' is already defined.}%
}
\newrobustcmd*\@trnslt@err@dict@not@defined[2]{%
  \@trnslt@error{%
    The \@trnslt@language{#2} dictionary entry for `#1' is not defined yet.%
  }%
}

% --------------------------------------------------------------------------
% check if babel or polyglossia is used
\AtEndPreamble{
  \@ifpackageloaded{babel}{}{
    \@ifpackageloaded{polyglossia}{}
      {\@trnslt@info{No language package found. I am going to use `english'
        as default language.}}
  }
  % define \languagename if not defined yet:
  \providecommand*\languagename{english}%
  \def\@trnslt@current@language{\languagename}%
  % define \bbl@afterfi if not defined yet:
  \ifdef\bbl@afterfi{}
    {\long\def\bbl@afterfi#1\fi{\fi#1}}
}

% --------------------------------------------------------------------------
% book keeping: the following macros will be used as `etoolbox' lists that
% keep record of defined languages, dialects and aliases
\newcommand*\@trnslt@languages{}% all languages
\newcommand*\@trnslt@aliases@pair{}% all aliases and their base
\newcommand*\@trnslt@aliases@single{}% all aliases
\newcommand*\@trnslt@dialects@pair{}% all dialects and their base
\newcommand*\@trnslt@dialects@single{}% all dialects

% --------------------------------------------------------------------------
% define \@trnslt@if@<name> conditionals that don't leave the checked macro as
% \relax behind and check for \@trnslt@<name>@#1.  These conditionals should
% also be expandable in an \edef-like context.  Thanks to e-TeX there's
% \ifcsname:
\newrobustcmd*\@trnslt@new@check[1]{%
  \csdef{@trnslt@if@#1}##1{%
    \ifcsname @trnslt@#1@##1\endcsname
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
  }%
}

% --------------------------------------------------------------------------
% leaves lowercase full expansion of #1 in the input stream (except that it
% doesn't, because nothing is expanded... :p)
\newcommand\@trnslt@get@lowercase[1]{%
  \lowercase\expandafter{\romannumeral-`\Q#1}%
}

% --------------------------------------------------------------------------
% \DeclareLanguage
% #1: language
\newrobustcmd*\DeclareLanguage[1]{%
  \@trnslt@declare@language{#1}}
\@onlypreamble\DeclareLanguage

\newrobustcmd*\@trnslt@declare@language[1]{%
  \@trnslt@if@language{#1}
    {}{%
      \csdef{@trnslt@language@#1}{#1}%
      \listeadd\@trnslt@languages{#1}%
    }%
}

% get the name declared by \DeclareLanguage: the underlying name of a given
% language; this is not the base of a dialect!
\newcommand*\@trnslt@language[1]{\csuse{@trnslt@language@#1}}

% a user-level equivalent:
% \newcommand*\baselanguage[1]{\@trnslt@language{#1}}

% define \@trnslt@if@language{#1}{}{} that actually checks the existence of
% \@trnslt@language@#1:
\@trnslt@new@check{language}

% --------------------------------------------------------------------------
% \DeclareLanguageDialect
% #1: dialect
% #2: language
\newrobustcmd*\DeclareLanguageDialect[2]{%
  \@trnslt@declare@languagedialect{#1}{#2}}
\@onlypreamble\DeclareLanguageDialect

\newrobustcmd*\@trnslt@declare@languagedialect[2]{%
  \@trnslt@if@language{#2}
    {}{%
      \@trnslt@warn@unknown@lang{#2}%
      \@trnslt@declare@language{#2}%
    }%
  \@trnslt@if@dialect{#1}
    {% => ist schon als dialect definiert => irgendwelche weiteren checks?
    }
    {%
      \@trnslt@if@alias{#2}
        {%
          \csedef{@trnslt@dialect@#1}{{\@trnslt@alias{#2}}{#1}}%
          \@trnslt@declare@language{#1}%
          \listeadd\@trnslt@dialects@single{#1}%
          \listeadd\@trnslt@dialects@pair{{#1}{\@trnslt@alias{#2}}}%
        }
        {%
          \csdef{@trnslt@dialect@#1}{{#2}{#1}}%
          \@trnslt@declare@language{#1}%
          \listeadd\@trnslt@dialects@single{#1}%
          \listeadd\@trnslt@dialects@pair{{#1}{#2}}%
        }%
    }%
}

% dialect equivalent of \@trnslt@language
\newcommand*\@trnslt@dialect[1]{\csuse{@trnslt@dialect@#1}}

% this macros fetches the base language for a given dialect, expandably:
\newcommand*\@trnslt@dialect@of[1]{%
  \@trnslt@if@dialect{#1}
    {%
      \expandafter\expandafter\expandafter
      \@firstoftwo
      \csname @trnslt@dialect@#1\endcsname
    }{}%
}

% get the underlying name of a language or the name of the base language of a
% dialect:
\newcommand*\baselanguage[1]{%
  \@trnslt@if@dialect{#1}
    {\@trnslt@language{\@trnslt@dialect@of{#1}}}
    {\@trnslt@language{#1}}%
}

% define \@trnslt@if@dialect{#1}{}{} that actually checks the existence of
% \@trnslt@dialect@#1: 
\@trnslt@new@check{dialect}

% --------------------------------------------------------------------------
% \DeclareLanguageAlias
% #1: alias
% #2: language
\newrobustcmd*\DeclareLanguageAlias[2]{%
  \@trnslt@declare@languagealias{#1}{#2}}
\@onlypreamble\DeclareLanguageAlias

\newrobustcmd*\@trnslt@declare@languagealias[2]{%
  \@trnslt@if@language{#2}
    {}{%
      \@trnslt@warn@unknown@lang{#2}%
      \@trnslt@declare@language{#2}%
    }%
  \csletcs{@trnslt@language@#1}{@trnslt@language@#2}%
  \@trnslt@if@dialect{#2}
    {\csletcs{@trnslt@dialect@#1}{@trnslt@dialect@#2}}
    {}%
  \ifinlist{#1}\@trnslt@aliases@single
    {}{%
      \csdef{@trnslt@alias@#1}{#2}%
      \listeadd\@trnslt@aliases@pair{{#1}{#2}}%
      \listeadd\@trnslt@aliases@single{#1}%
    }%
}

% alias equivalent of \@trnslt@language
\newcommand*\@trnslt@alias[1]{\csuse{@trnslt@alias@#1}}

% define \@trnslt@if@alias{#1}{}{} that actually checks the existence of
% \@trnslt@alias@#1: 
\@trnslt@new@check{alias}

% --------------------------------------------------------------------------
% check the current language, expandably:
% #1: language
% #2: true
% #3: false
\newcommand*\@trnslt@iflanguage[1]{%
  \cnltx@braced@expanded@fully
  \cnltx@braced@expanded@fully
  \cnltx@firstofone
  \cnltx@ifstrequal
    {\@trnslt@language{#1}}
    {\@trnslt@language{\languagename}}%
}

% check the current /base/ language, expandably:
\newcommand*\@trnslt@ifbaselanguage[1]{%
  \@trnslt@if@dialect{\languagename}
    {%
      \cnltx@braced@expanded@fully
      \cnltx@braced@expanded@fully
      \cnltx@firstofone
      \cnltx@ifstrequal
        {\@trnslt@language{\@trnslt@dialect@of{\languagename}}}
        {\@trnslt@language{#1}}%
    }
    {\@trnslt@iflanguage{#1}}%
}

% user commands for the above:
\newcommand*\ifcurrentlanguage[1]{%
  \@trnslt@iflanguage{#1}%
}
\newcommand*\ifcurrentbaselanguage[1]{%
  \@trnslt@ifbaselanguage{#1}%
}

% --------------------------------------------------------------------------
% Now that we can define languages we also want to be able to define
% translations:
% \DeclareTranslation, \NewTranslation, \RenewTranslation and
% \ProvideTranslation
% #1: language
% #2: word
% #3: replacement
\newrobustcmd*\DeclareTranslation[3]{%
  \@trnslt@declare@translation{#2}{#1}{#3}%
}
\@onlypreamble\DeclareTranslation

\newrobustcmd*\DeclareTranslationFallback[2]{%
  \@trnslt@declare@translation{#1}{fallback}{#2}%
}
\@onlypreamble\DeclareTranslationFallback

\newrobustcmd*\NewTranslation[3]{%
  \@trnslt@new@translation{#2}{#1}{#3}%
}
\@onlypreamble\NewTranslation

\newrobustcmd*\RenewTranslation[3]{%
  \@trnslt@renew@translation{#2}{#1}{#3}%
}
\@onlypreamble\RenewTranslation

\newrobustcmd*\ProvideTranslation[3]{%
  \@trnslt@provide@translation{#2}{#1}{#3}%
}
\@onlypreamble\ProvideTranslation

% #1: word
% #2: language
% #3: replacement
\newrobustcmd*\@trnslt@declare@translation[3]{%
  \@trnslt@if@language{#2}
    {%
      \@trnslt@if@dialect{#2}
        {%
          \csdef{@trnslt@word@\detokenize{#1}@\@trnslt@dialect{#2}}{#3}%
          \@trnslt@if@word\@trnslt@dialect@of{#1}{#2}
            {}
            {\csdef{@trnslt@word@\detokenize{#1}@\@trnslt@dialect@of{#2}}{#3}}%
        }
        {\csdef{@trnslt@word@\detokenize{#1}@\@trnslt@language{#2}}{#3}}%
      % save the <word> as <word>:
      \csdef{@trnslt@word@\detokenize{#1}@literal}{#1}%
    }
    {\@trnslt@err@unknown@lang{#2}}%
}

\newrobustcmd*\@trnslt@new@translation[3]{%
  \@trnslt@if@word\@trnslt@language{#1}{#2}
    {\@trnslt@err@already@defined{#1}{#2}}
    {\@trnslt@declare@translation{#1}{#2}{#3}}%
}

\newrobustcmd*\@trnslt@renew@translation[3]{%
  \@trnslt@if@word\@trnslt@language{#1}{#2}
    {\@trnslt@declare@translation{#1}{#2}{#3}}
    {\@trnslt@err@not@defined{#1}{#2}}%
}

\newrobustcmd*\@trnslt@provide@translation[3]{%
  \@trnslt@if@word\@trnslt@language{#1}{#2}
    {}
    {\@trnslt@declare@translation{#1}{#2}{#3}}%
}

% --------------------------------------------------------------------------
% let's go through some trouble to check if a translation exists:
\newcommand*\@trnslt@if@word[3]{%
  \ifcsname @trnslt@word@\detokenize{#2}@#1{#3}\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}%

\newcommand*\@trnslt@if@translation[2]{%
  \@trnslt@if@word\@trnslt@language{#1}{#2}
    {\expandafter\@firstoftwo}
    {%
      \@trnslt@if@dialect{#2}
        {%
          \@trnslt@if@word\@trnslt@dialect{#1}{#2}
            {\expandafter\@firstoftwo}
            {%
              \@trnslt@if@word\@trnslt@dialect@of{#1}{#2}
                {\expandafter\@firstoftwo}
                {\expandafter\@secondoftwo}%
            }
        }
        {\expandafter\@secondoftwo}%
    }%
}

% --------------------------------------------------------------------------
% We also need to be able to look up a translation:
% \GetTranslationFor and \GetTranslation
% these need to be expandable!
% #1: language
% #2: word
\newcommand*\GetTranslationFor[2]{%
  \@trnslt@checkandget@translation@for{#2}{#1}}

\newcommand*\GetTranslation[1]{%
  \@trnslt@checkandget@translation@for{#1}{\@trnslt@current@language}}

% those will print the translation lowercase... they're also expandable; that
% is: nearly...
%   \DeclareTranslation{German}{foo}{Bla}
%   \edef\foo{\GetLCTranslationFor{German}{foo}}
%   \show\foo
%   > \foo=macro:
%   ->\lowercase {Bla}.
\newcommand*\GetLCTranslationFor[2]{%
  \@trnslt@get@lowercase{\@trnslt@checkandget@translation@for{#2}{#1}}%
}

\newcommand*\GetLCTranslation[1]{%
  \@trnslt@get@lowercase{%
    \@trnslt@checkandget@translation@for{#1}{\@trnslt@current@language}%
  }%
}

% unexpandable version of the commands that raise a warning if no translation
% is available:
\newrobustcmd*\GetTranslationForWarn[2]{%
  \@trnslt@getandwarn@translation@for{#2}{#1}%
}

\newrobustcmd*\GetTranslationWarn[1]{%
  \@trnslt@getandwarn@translation@for{#1}{\@trnslt@current@language}%
}

\newrobustcmd*\GetLCTranslationForWarn[2]{%
  \@trnslt@getandwarn@lctranslation@for{#2}{#1}%
}

\newrobustcmd*\GetLCTranslationWarn[1]{%
  \@trnslt@getandwarn@lctranslation@for{#1}{\@trnslt@current@language}%
}

% #1: word #2: language
\newcommand*\@trnslt@get@translation@for[2]{%
  \@trnslt@if@dialect{#2}
    {%
      \ifcsdef{@trnslt@word@\detokenize{#1}@\@trnslt@dialect{#2}}
        {\csuse{@trnslt@word@\detokenize{#1}@\@trnslt@dialect{#2}}}
        {\csuse{@trnslt@word@\detokenize{#1}@\@trnslt@dialect@of{#2}}}%
    }
    {\csuse{@trnslt@word@\detokenize{#1}@\@trnslt@language{#2}}}%
}

\newcommand*\@trnslt@checkandget@translation@for[2]{%
  \@trnslt@if@translation{#1}{#2}
    {\@trnslt@get@translation@for{#1}{#2}}
    {%
      \@trnslt@if@translation{#1}{fallback}
        {\csuse{@trnslt@word@\detokenize{#1}@fallback}}
        {\csuse{@trnslt@word@\detokenize{#1}@literal}}%
    }%
}

% this is not expandable!
\newrobustcmd*\@trnslt@getandwarn@translation@for[2]{%
  \@trnslt@if@translation{#1}{#2}
    {\@trnslt@get@translation@for{#1}{#2}}
    {%
      \@trnslt@warning{Translation for `#1' in #2 unknown. You may try to use
        \string\DeclareTranslation{#2}{#1}{ ... } in your preamble.}%
      \@trnslt@if@translation{#1}{fallback}
        {%
          \@trnslt@info{Using fallback translation for `#1'}%
          \csuse{@trnslt@word@\detokenize{#1}@fallback}
        }
        {\csuse{@trnslt@word@\detokenize{#1}@literal}}%
    }%
}

% lowercase version for translation with warnings:
\newrobustcmd*\@trnslt@getandwarn@lctranslation@for[2]{%
  \@trnslt@if@translation{#1}{#2}
    {\@trnslt@get@lowercase{\@trnslt@get@translation@for{#1}{#2}}}
    {%
      \@trnslt@warning{Translation for `#1' in #2 unknown. You may try to use
        \string\DeclareTranslation{#2}{#1}{ ... } in your preamble.}%
      \@trnslt@if@translation{#1}{fallback}
        {%
          \@trnslt@info{Using fallback translation for `#1'}%
          \@trnslt@get@lowercase{\csuse{@trnslt@word@\detokenize{#1}@fallback}}%
        }
        {\@trnslt@get@lowercase{\csuse{@trnslt@word@\detokenize{#1}@literal}}}%
    }%
}

% --------------------------------------------------------------------------
% no idea if the following ones really are needed... let's define them
% anyway
% \SaveTranslationFor and \SaveTranslation
\newrobustcmd*\SaveTranslationFor[3]{%
  \@trnslt@save@translation@for{#1}{#3}{#2}%
}

\newrobustcmd*\SaveTranslation[2]{%
  \@trnslt@save@translation@for{#1}{#2}{\@trnslt@current@language}%
}

\newrobustcmd*\@trnslt@save@translation@for[3]{%
  \edef#1{%
    \@trnslt@if@translation{#2}{#3}
      {%
        \unexpanded\expandafter\expandafter\expandafter
        {\csname @trnslt@word@\detokenize{#2}@\@trnslt@language{#3}\endcsname}%
      }
      {}%
  }%
}

% --------------------------------------------------------------------------
% The basics are set. What's missing? Right: dictionaries! Those will be files
% that contain translations for a specific language.
% --------------------------------------------------------------------------
% load dictionaries and check for existing ones:
% \LoadDictionary and \LoadDictionaryFor
\newrobustcmd*\LoadDictionary[1]{%
  \@trnslt@load@dictionary@for{#1}{\@trnslt@current@language}}
\@onlypreamble\LoadDictionary

\newrobustcmd*\LoadDictionaryFor[2]{%
  \@trnslt@load@dictionary@for{#2}{#1}}
\@onlypreamble\LoadDictionaryFor

% #1: name
% #2: lang
\newrobustcmd*\@trnslt@load@dictionary@for[2]{%
  \AtBeginDocument{%
    \InputIfFileExists{#1-\@trnslt@language{#2}.trsl}
      {\@trnslt@check@dictionary{#1}{#2}}
      {%
        \@trnslt@warning{dictionary file `#1-\@trnslt@language{#2}.trsl' not
          found.}%
      }%
  }%
}

\newrobustcmd*\@trnslt@check@dictionary[2]{%
  \AfterFile{#1-\@trnslt@language{#2}.trsl}
    {%
      \ifcsdef{@trnslt@dictionary@#1@\@trnslt@language{#2}}
        {\@trnslt@info{loading dictionary `#1' for `#2'.}}
        {%
          \@trnslt@warning{file `#1-\@trnslt@language{#2}.trsl' does not
            appear to be a dictionary}%
        }%
    }%
}

\newcommand*\@trnslt@if@dictionary[2]{\IfFileExists{#1-#2.trsl}}

\newcommand*\@trnslt@load@dictionary@silent@for[2]{\InputIfFileExists{#1-#2.trsl}{}{}}

% --------------------------------------------------------------------------
% the contents of a dictionary; let's declare that is one.
\newrobustcmd*\ProvideDictionaryFor[2]{%
  \@trnslt@provide@dictionary@for{#1}{#2}}
\@onlypreamble\ProvideDictionaryFor

\newrobustcmd*\@trnslt@provide@dictionary@for[2]{%
  \def\@trnslt@dictionary@name{#2}%
  \edef\@trnslt@dictionary@lang{\@trnslt@language{#1}}%
  % this macro can be used to check if we have a dictionary and will also be
  % used as a list for the dictionary entries:
  \csdef{@trnslt@dictionary@\@trnslt@dictionary@name @\@trnslt@dictionary@lang}{}%
  \@ifnextchar[
    {\@trnslt@provide@dictionary@version}
    {
      \ProvidesFile
        {#2-\@trnslt@dictionary@lang.trsl}%
        [(\@trnslt@dictionary@lang\space translation file `#2')]
    }%
}

\protected\def\@trnslt@provide@dictionary@version[#1]{%
  \ProvidesFile
    {\@trnslt@dictionary@name-\@trnslt@dictionary@lang.trsl}%
    [(\@trnslt@dictionary@lang\space translation file `\@trnslt@dictionary@name') #1]}

% change this test (we can't use braces inside the item with \ifinlist):
\newcommand*\@trnslt@check@dictionary@entry[2]{%
  \cnltx@ifinlistcs
    {{#1}{#2}}
    {@trnslt@dictionary@\@trnslt@dictionary@name @\@trnslt@dictionary@lang}%
}

\newrobustcmd*\@trnslt@add@dictionary@entry[2]{%
  \listcsadd
    {@trnslt@dictionary@\@trnslt@dictionary@name @\@trnslt@dictionary@lang}
    {{#1}{#2}}%
}

% --------------------------------------------------------------------------
% now we should be able to add translations without repeatedly type the
% language ...
\newrobustcmd*\NewDictTranslation[2]{%
  \@trnslt@check@dictionary@entry{#1}{#2}
    {\@trnslt@err@dict@already@defined{#1}{#2}}%
    {%
      \@trnslt@add@dictionary@entry{#1}{#2}
      \@trnslt@new@translation{#1}{\@trnslt@dictionary@lang}{#2}%
    }%
}
\@onlypreamble\NewDictTranslation

\newrobustcmd*\RenewDictTranslation[2]{%
  \@trnslt@check@dictionary@entry{#1}{#2}
    {\@trnslt@renew@translation{#1}{\@trnslt@dictionary@lang}{#2}}
    {\@trnslt@err@dict@not@defined{#1}{#2}}%
}
\@onlypreamble\RenewDictTranslation

\newrobustcmd*\DeclareDictTranslation[2]{%
  \@trnslt@check@dictionary@entry{#1}{#2}
    {}
    {\@trnslt@add@dictionary@entry{#1}{#2}}%
  \@trnslt@declare@translation{#1}{\@trnslt@dictionary@lang}{#2}%
}
\@onlypreamble\DeclareDictTranslation

\newrobustcmd*\ProvideDictTranslation[2]{%
  \@trnslt@check@dictionary@entry{#1}{#2}
    {}
    {%
      \@trnslt@add@dictionary@entry{#1}{#2}%
      \@trnslt@provide@translation{#1}{\@trnslt@dictionary@lang}{#2}%
    }%
}
\@onlypreamble\ProvideDictTranslation

% --------------------------------------------------------------------------
% last not least let's inspect which entries a dictionary contains of:
% \PrintDictionaryFor
% #1: lang
% #2: name
% #3: pre
% #4: mid
% #5: post
\newcommand*\PrintDictionaryFor[5]{%
  \@trnslt@print@dictionary@for{#1}{#2}{#3}{#4}{#5}%
}

% #1: lang
% #2: name
% #3: pre
% #4: mid
% #5: post
\newcommand*\@trnslt@print@dictionary@for[5]{%
  \forlistcsloop
    {\@trnslt@print@dictionary@entry{#3}{#4}{#5}}
    {@trnslt@dictionary@#2@\@trnslt@language{#1}}%
}

% #1: pre
% #2: mid
% #3: post
% #4: (key)(translation)
\newcommand*\@trnslt@print@dictionary@entry[4]{%
  \@trnslt@print@dictionary@entry@aux{#1}{#2}{#3}#4%
}

% #1: pre
% #2: mid
% #3: post
% #4: key
% #5: translation
\newcommand*\@trnslt@print@dictionary@entry@aux[5]{#1#4#2#5#3}

% ==========================================================================
% Now that the package is finished let's us ethe above commands to provide a
% basis for usage; we need all languages known to `babel' and `polyglossia'
% as well as aliases to allow different spellings/names; we also need dialects
% where it makes sense (e.g. British as a dialect of English)

% --------------------------------------------------------------------------
% dummy language `fallback' -- it is needed for the whole mechansim provided
% earlier (\DeclareFallbackTranslation...)
\DeclareLanguage{fallback}
\DeclareLanguageAlias{Fallback}{fallback}

% --------------------------------------------------------------------------
% predefined languages
\DeclareLanguage{afrikaans}
\DeclareLanguage{albanian}
\DeclareLanguage{amharic}
\DeclareLanguage{arabic}
\DeclareLanguage{armenian}
\DeclareLanguage{asturian}
\DeclareLanguage{basque}
\DeclareLanguage{bengali}
\DeclareLanguage{breton}
\DeclareLanguage{bulgarian}
\DeclareLanguage{catalan}
\DeclareLanguage{coptic}
\DeclareLanguage{czech}
\DeclareLanguage{danish}
\DeclareLanguage{dutch}
\DeclareLanguage{english}
\DeclareLanguage{esperanto}
\DeclareLanguage{estonian}
\DeclareLanguage{ethiop}
\DeclareLanguage{farsi}
\DeclareLanguage{finnish}
\DeclareLanguage{french}
\DeclareLanguage{friulan}
\DeclareLanguage{gaelic}
\DeclareLanguage{galician}
\DeclareLanguage{german}
\DeclareLanguage{greek}
\DeclareLanguage{hebrew}
\DeclareLanguage{hindustani}
\DeclareLanguage{hungarian}
\DeclareLanguage{icelandic}
\DeclareLanguage{interlingua}
\DeclareLanguage{italian}
\DeclareLanguage{japanese}
\DeclareLanguage{kannada}
\DeclareLanguage{korean}
\DeclareLanguage{ladin}
\DeclareLanguage{lao}
\DeclareLanguage{latin}
\DeclareLanguage{latvian}
\DeclareLanguage{lithuanian}
\DeclareLanguage{malay}
\DeclareLanguage{malayalam}
\DeclareLanguage{maldivian}
\DeclareLanguage{marathi}
\DeclareLanguage{mongolian}
% polyglossia seems to support this one but it is unclear which language is
% actually meant by it:
% \DeclareLanguage{nko}
\DeclareLanguage{norwegian}
\DeclareLanguage{occitan}
\DeclareLanguage{piedmontese}
\DeclareLanguage{pinyin}
\DeclareLanguage{polish}
\DeclareLanguage{portuges}
\DeclareLanguage{romanian}
\DeclareLanguage{romansh}
\DeclareLanguage{russian}
\DeclareLanguage{samin}
\DeclareLanguage{sanskrit}
\DeclareLanguage{serbocroatian}
\DeclareLanguage{slovak}
\DeclareLanguage{slovenian}
\DeclareLanguage{sorbian}
% not sure about this: isn't it either a Spanish or English dialect?
\DeclareLanguage{spanglish}
\DeclareLanguage{spanish}
\DeclareLanguage{swedish}
% polyglossia seems to support this one but it is unclear which language is
% actually meant by it:
% \DeclareLanguage{syriac}
\DeclareLanguage{tamil}
\DeclareLanguage{telugu}
\DeclareLanguage{thai}
\DeclareLanguage{tibetan}
\DeclareLanguage{turkish}
\DeclareLanguage{turkmen}
\DeclareLanguage{ukrainian}
\DeclareLanguage{vietnamese}
\DeclareLanguage{welsh}

% --------------------------------------------------------------------------
% aliases and dialects:
\DeclareLanguageAlias  {Afrikaans}{afrikaans}
\DeclareLanguageAlias  {Albanian}{albanian}
\DeclareLanguageAlias  {Amharic}{amharic}
\DeclareLanguageAlias  {Arabic}{arabic}
\DeclareLanguageAlias  {Armenian}{armenian}
\DeclareLanguageAlias  {Asturian}{asturian}
\DeclareLanguageAlias  {astur-leonese}{asturian}
\DeclareLanguageAlias  {Astur-Leonese}{astur-leonese}
\DeclareLanguageAlias  {asturian-leonese}{asturian}
\DeclareLanguageAlias  {Asturian-Leonese}{asturian-leonese}
\DeclareLanguageAlias  {Basque}{basque}
\DeclareLanguageAlias  {Bengali}{bengali}
\DeclareLanguageAlias  {Breton}{breton}
\DeclareLanguageAlias  {Bulgarian}{bulgarian}
\DeclareLanguageAlias  {Catalan}{catalan}
\DeclareLanguageAlias  {Coptic}{coptic}
\DeclareLanguageAlias  {coptic egyptian}{coptic}
\DeclareLanguageAlias  {Coptic Egyptian}{coptic egyptian}
\DeclareLanguageAlias  {Czech}{czech}
\DeclareLanguageAlias  {Danish}{danish}
\DeclareLanguageAlias  {Dutch}{dutch}
\DeclareLanguageAlias  {Farsi}{farsi}
\DeclareLanguageAlias  {Finnish}{finnish}
\DeclareLanguageAlias  {francais}{french}
\DeclareLanguageAlias  {Francais}{francais}
\DeclareLanguageDialect{canadien}{french}
\DeclareLanguageAlias  {Canadien}{canadien}
\DeclareLanguageAlias  {French}{french}
\DeclareLanguageDialect{acadian}{french}
\DeclareLanguageAlias  {Acadian}{acadian}
\DeclareLanguageAlias  {frenchle}{french}
\DeclareLanguageDialect{american}{english}
\DeclareLanguageAlias  {American}{american}
\DeclareLanguageDialect{australian}{english}
\DeclareLanguageAlias  {Australian}{australian}
\DeclareLanguageDialect{british}{english}
\DeclareLanguageAlias  {British}{british}
\DeclareLanguageDialect{canadian}{english}
\DeclareLanguageAlias  {Canadian}{canadian}
\DeclareLanguageAlias  {English}{english}
\DeclareLanguageAlias  {UKenglish}{british}
\DeclareLanguageAlias  {USenglish}{american}
\DeclareLanguageDialect{newzealand}{english}
\DeclareLanguageAlias  {Newzealand}{newzealand}
\DeclareLanguageAlias  {Ethiop}{ethiop}
\DeclareLanguageAlias  {Esperanto}{esperanto}
\DeclareLanguageAlias  {Estonian}{estonian}
\DeclareLanguageAlias  {Friulan}{friulan}
\DeclareLanguageAlias  {Gaelic}{gaelic}
\DeclareLanguageDialect{irish}{gaelic}
\DeclareLanguageDialect{scottish}{gaelic}
\DeclareLanguageAlias  {Irish}{irish}
\DeclareLanguageAlias  {irish gaelic}{irish}
\DeclareLanguageAlias  {Irish Gaelic}{irish}
\DeclareLanguageAlias  {Scottish}{scottish}
\DeclareLanguageAlias  {scottish gaelic}{scottish}
\DeclareLanguageAlias  {Scottish Gaelic}{scottish}
\DeclareLanguageAlias  {Galician}{galician}
\DeclareLanguageAlias  {German}{german}
\DeclareLanguageAlias  {germanb}{german}
\DeclareLanguageAlias  {ngerman}{german}
\DeclareLanguageDialect{austrian}{german}
\DeclareLanguageAlias  {Austrian}{austrian}
\DeclareLanguageAlias  {naustrian}{austrian}
\DeclareLanguageAlias  {Greek}{greek}
\DeclareLanguageAlias  {polutonikogreek}{greek}
\DeclareLanguageAlias  {ibygreek}{greek}
\DeclareLanguageAlias  {bgreek}{greek}
\DeclareLanguageAlias  {Hebrew}{hebrew}
\DeclareLanguageAlias  {Hindustani}{hindustani}
\DeclareLanguageAlias  {hindi-urdu}{hindustani}
\DeclareLanguageAlias  {Hindi-Urdu}{hindi-urdu}
\DeclareLanguageDialect{hindi}{hindustani}
\DeclareLanguageAlias  {Hindi}{hindi}
\DeclareLanguageDialect{urdu}{hindustani}
\DeclareLanguageAlias  {Urdu}{urdu}
\DeclareLanguageAlias  {Hungarian}{hungarian}
\DeclareLanguageAlias  {magyar}{hungarian}
\DeclareLanguageAlias  {Magyar}{magyar}
\DeclareLanguageAlias  {Icelandic}{icelandic}
\DeclareLanguageAlias  {Interlingua}{interlingua}
\DeclareLanguageAlias  {Italian}{italian}
\DeclareLanguageAlias  {Japanese}{japanese}
\DeclareLanguageAlias  {Kannada}{kannada}
\DeclareLanguageAlias  {Korean}{korean}
\DeclareLanguageAlias  {Ladin}{ladin}
\DeclareLanguageAlias  {Lao}{lao}
\DeclareLanguageAlias  {laotian}{lao}
\DeclareLanguageAlias  {Laotian}{laotian}
\DeclareLanguageAlias  {Latin}{latin}
\DeclareLanguageAlias  {Latvian}{latvian}
\DeclareLanguageAlias  {lettish}{latvian}
\DeclareLanguageAlias  {Lettish}{lettish}
\DeclareLanguageAlias  {Lithuanian}{lithuanian}
% hopefully someone who knows better than me can comment on these
\DeclareLanguageAlias  {Malay}{malay}
\DeclareLanguageDialect{indonesian}{malay}
\DeclareLanguageAlias  {Indonesian}{indonesian}
\DeclareLanguageAlias  {indon}{indonesian}
\DeclareLanguageAlias  {bahasa meyalu}{malay}
\DeclareLanguageAlias  {Bahasa Meyalu}{bahasa meyalu}
\DeclareLanguageAlias  {bahasa}{bahasa meyalu}
\DeclareLanguageAlias  {Bahasa}{bahasa}
\DeclareLanguageAlias  {bahasai}{bahasa}
\DeclareLanguageAlias  {bahasam}{bahasa}
\DeclareLanguageAlias  {Malayalam}{malayalam}
\DeclareLanguageAlias  {Maldivian}{maldivian}
\DeclareLanguageAlias  {divehi}{maldivian}
\DeclareLanguageAlias  {Divehi}{divehi}
\DeclareLanguageAlias  {Marathi}{marathi}
\DeclareLanguageAlias  {Mongolian}{mongolian}
% \DeclareLanguageAlias  {Syriac}{syriac}
\DeclareLanguageAlias  {norsk}{norwegian}
\DeclareLanguageAlias  {Norsk}{norsk}
\DeclareLanguageAlias  {Norwegian}{norwegian}
\DeclareLanguageAlias  {nynorsk}{norwegian}
\DeclareLanguageAlias  {Nynorsk}{nynorsk}
\DeclareLanguageAlias  {Occitan}{occitan}
\DeclareLanguageAlias  {lenga d'oc}{occitan}
\DeclareLanguageAlias  {langue d'oc}{occitan}
\DeclareLanguageAlias  {Piedmontese}{piedmontese}
\DeclareLanguageAlias  {piemontese}{piedmontese}
\DeclareLanguageAlias  {Piemontese}{piemontese}
\DeclareLanguageAlias  {piemonteis}{piedmontese}
\DeclareLanguageAlias  {Piemonteis}{piemonteis}
\DeclareLanguageAlias  {Pinyin}{pinyin}
\DeclareLanguageAlias  {Polish}{polish}
\DeclareLanguageDialect{brazil}{portuges}
\DeclareLanguageAlias  {Brazil}{brazil}
\DeclareLanguageAlias  {brazilian}{brazil}
\DeclareLanguageAlias  {Brazilian}{brazilian}
\DeclareLanguageAlias  {Portuges}{portuges}
\DeclareLanguageAlias  {portuguese}{portuges}
\DeclareLanguageAlias  {Portuguese}{portuguese}
\DeclareLanguageAlias  {Romanian}{romanian}
\DeclareLanguageAlias  {Romansh}{romansh}
\DeclareLanguageAlias  {Romansch}{romansh}
\DeclareLanguageAlias  {Rumantsh}{romansh}
\DeclareLanguageAlias  {Rumantsch}{romansh}
\DeclareLanguageAlias  {Romanche}{romansh}
\DeclareLanguageAlias  {Russian}{russian}
\DeclareLanguageAlias  {Samin}{samin}
\DeclareLanguageAlias  {north sami}{samin}
\DeclareLanguageAlias  {North Sami}{north sami}
\DeclareLanguageAlias  {northern sami}{north sami}
\DeclareLanguageAlias  {Northern Sami}{northern sami}
\DeclareLanguageAlias  {Sanskrit}{sanskrit}
% this one isn't needed, or is it? vvv
\DeclareLanguageAlias  {Serbocroatian}{serbocroatian}
\DeclareLanguageAlias  {serbo-croatian}{serbocroatian}
\DeclareLanguageAlias  {Serbo-Croatian}{serbocroatian}
\DeclareLanguageDialect{serbian}{serbocroatian}
\DeclareLanguageAlias  {Serbian}{serbian}
\DeclareLanguageAlias  {serbianc}{serbian}
\DeclareLanguageDialect{croatian}{serbocroatian}
\DeclareLanguageAlias  {Croatian}{croatian}
\DeclareLanguageAlias  {Slovak}{slovak}
\DeclareLanguageAlias  {Slovenian}{slovenian}
\DeclareLanguageAlias  {Sorbian}{sorbian}
\DeclareLanguageDialect{lowersorbian}{sorbian}
\DeclareLanguageDialect{uppersorbian}{sorbian}
\DeclareLanguageAlias  {Lowersorbian}{lowersorbian}
\DeclareLanguageAlias  {Uppersorbian}{uppersorbian}
\DeclareLanguageAlias  {lsorbian}{lowersorbian}
\DeclareLanguageAlias  {usorbian}{uppersorbian}
\DeclareLanguageAlias  {lower sorbian}{lowersorbian}
\DeclareLanguageAlias  {upper sorbian}{uppersorbian}
\DeclareLanguageAlias  {Lower Sorbian}{lowersorbian}
\DeclareLanguageAlias  {Upper Sorbian}{uppersorbian}
\DeclareLanguageAlias  {Spanglish}{spanglish}
\DeclareLanguageAlias  {Spanish}{spanish}
\DeclareLanguageAlias  {Swedish}{swedish}
\DeclareLanguageDialect{swissgerman}{german}
% this is to be discussed: swiss could also be an alias of french, italian or
% romansh:
\DeclareLanguageAlias  {swiss}{swissgerman}
\DeclareLanguageAlias  {Swiss}{swiss}
\DeclareLanguageAlias  {Swissgerman}{swissgerman}
\DeclareLanguageAlias  {swiss german}{swissgerman}
\DeclareLanguageAlias  {Swiss German}{swiss german}
\DeclareLanguageAlias  {Tamil}{tamil}
\DeclareLanguageAlias  {Telugu}{telugu}
\DeclareLanguageAlias  {Thai}{thai}
\DeclareLanguageAlias  {thaicjk}{thai}
\DeclareLanguageAlias  {Thaicjk}{thaicjk}
\DeclareLanguageAlias  {Tibetan}{tibetan}
\DeclareLanguageAlias  {Turkish}{turkish}
\DeclareLanguageAlias  {Turkmen}{turkmen}
\DeclareLanguageAlias  {Ukrainian}{ukrainian}
\DeclareLanguageAlias  {Vietnamese}{vietnamese}
\DeclareLanguageAlias  {Welsh}{welsh}

% ==========================================================================
% OK, we have everything, do we? No, wait: let's load the basic dictionary
% that is part of this package if it is available for the document language
% --------------------------------------------------------------------------
% load basic dictionary if available
\AtBeginDocument{%
  \@trnslt@if@dialect{\@trnslt@current@language}
    {%
      \@trnslt@if@dictionary
        {translations-basic-dictionary}
        {\@trnslt@language{\@trnslt@current@language}}%
        {%
          \@trnslt@load@dictionary@silent@for
            {translations-basic-dictionary}
            {\@trnslt@language{\@trnslt@current@language}}%
        }%
        {%
          \@trnslt@load@dictionary@silent@for
            {translations-basic-dictionary}
            {\@trnslt@dialect@of{\@trnslt@current@language}}%
        }
    }
    {%
      \@trnslt@load@dictionary@silent@for
        {translations-basic-dictionary}
        {\@trnslt@language{\@trnslt@current@language}}%
    }%
}

\endinput

% ==========================================================================
% HISTORY:
2012/09/30 v0.2beta - first version (as part of the `exsheets' bundle)
2012/10/05 v0.2     - \LoadDictionary and \LoadDictionaryFor added and loads of
                      languages defined.
2013/03/10 v0.8     - basic dictionaries for English, German, French and Spanish
                    - new command \DeclareDictTranslation
2013/04/04 v0.8a    - bug fix in \DeclareDictTranslation
2013/04/07 v0.9     - slightly improved messages
2013/04/08 v0.9a    - changed fallback warning into info
                    - synchronized version number with `exsheets' until now but
                      won't any more
2013/06/22 v0.9b    - added Swiss
2013/06/28 v0.10    - declaring aliases of dialects now works as expected
                    - declarings dialects of an alias now correctly declares
                      the dialect to the correct base language
                    - corrected a few erroneous language declarations
2013/07/12 v0.10a   - \GetTranslation gets two-folded fallback: use
                      fallback-translation if no translation for the current
                      language has been defined; use literal string if /no/
                      language is used - this should never happen but /will/
                      happen if neither `babel' nor `polyglossia' have been
                      loaded, i.e., no language has been chosen /and/ the
                      package writer did not provide an English translation
2013/07/16 v1.0     - removed from `exsheets' bundle - `translations' should
                      be a package of it's own
                    - load basic dictionary automatically if available
                    - rudimentary check in \LoadDictionary if loaded file is a
                      dictionary
                    - new command \PrintDictionaryFor
                    - redefined conditionals; they still seemed to make
                      trouble in some cases
2013/08/05 v1.1     - added /loads/ of languages, now the list of babel and
                      polyglossia languages hopefully is complete
                    - a few languages had falsely been declared as dialect
                      instead of an alias
                    - added weekday names and month names to basic dictionary
                    - new command \baselanguage
                    - new commands \GetLCTranslation, \GetLCTranslationFor,
                      \GetLCTranslationWarn and \GetLCTranslationForWarn
                    - load basic dictionary also for dialects and if it
                      doesn't exist load it for the corresponding base
                      language instead
2013/09/30 v1.1a    - Bug fix in \NewTranslation und \RenewTranslation
2014/01/10 v1.2     - \ifcurrentlanguage, \ifcurrentbaselanguage
                    - require cnltx-base
                    - change the `no language package' warning into an info
                    - \ProvideTranslation
                    - \NewDictTranslation, \RenewDictTranslation,
                      \ProvideDictTranslation
                    - translations in dictionaries are provided
                    - \baselanguagename
2014/01/23 v1.2a    - add \detokenize{} so that translation keys with
                      non-ascii chars can safely be used
                    - fix bug in dialect declaration
                    - rename \baselanguagename => \baselanguage
                    - drop earlier \baselanguage (it was and still is
                      available as \@trnslt@language)
2015/07/09 v1.2b    - add language `korean'
2015/08/29 v1.2c    - fix bug in \@trnslt@save@translation@for