%D \module
%D   [       file=lang-lab,
%D        version=1997.08.27,
%D          title=\CONTEXT\ Language Macros,
%D       subtitle=Language Head and Label Texts,
%D         author=Hans Hagen / Tobias Burnus,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

\writestatus{loading}{Language Head and Label Texts}

\unprotect

%D In this module we deal with language dependant labels and
%D prefixes, like in {\em Figure~12} and {\em Chapter 1}. In
%D this file we set the default values. Users can easily
%D overrule these.
%D
%D This module is dedicated to the grandfather of Tobias
%D Burnus, who's extensive languages oriented library helped us
%D a lot in finding the right translations. All those labels 
%D are collected in files that reflect their common ancestor.
%D
%D Not all languages can be satisfied with the labeling
%D mechanism as provided here. Chinese for instance put a label
%D in front as well as after a part number. This is why the 
%D current implementation of labels supports two labels too. 

%D \macros
%D   {setupheadtext, setuplabeltext}
%D
%D First we present some macros that deal with what we will
%D call head and label texts. Such texts are defines by:
%D
%D \showsetup{\y!setupheadtext}
%D \showsetup{\y!setuplabeltext}
%D
%D In a few paragraphs we'll show quite a lot of examples
%D of its use.

\def\setupheadtext%
  {\dosetupsometextprefix\c!titel}

\def\setuplabeltext%
  {\dosetupsometextprefix\c!label}

\let\handletextprefix=\relax

\def\dodosetupsometextprefix#1%
  {\def\dododosetupsometextprefix[##1][##2]%
     {\ifsecondargument
        \def\docommando####1{\dodocommando[#1##1][####1]}%
        \processcommalist[##2]\docommando
      \else
        \def\docommando####1{\dodocommando[#1\currentmainlanguage][####1]}%
        \processcommalist[##1]\docommando
      \fi}%
   \dodoubleempty\dododosetupsometextprefix}

\def\doassignsometextprefix[#1][#2,#3,#4]%
  {\setvalue{#1}{\handletextprefix{#2}{#3}}}

\def\dosetupsometextprefix#1%
  {\def\dodocommando[##1][##2=##3]%
     {\doassignsometextprefix[##1##2][##3,,]}%
   \dodosetupsometextprefix{#1}}

%D By changing the meaning of \type {\handletextprefix} we 
%D can filter the left and right labeltext as well as convert 
%D labels to uppercase. 
%D
%D These commands accept all kind of inputs: 
%D
%D \starttypen
%D \setuplabeltext [language] [label=text]
%D \setuplabeltext [language] [label=text,label=text,...]
%D \setuplabeltext            [label=text]
%D \setuplabeltext            [label=text,label=text,...]
%D \stoptypen
%D 
%D The last two cases concern the current language. 

%D \macros
%D   {headtext, 
%D    labeltext, leftlabeltext, rightlabeltext, labeltexts,
%D    LABELTEXT, LEFTLABELTEXT, RIGHTLABELTEXT, LABELTEXTS}
%D
%D Once defined, head and label texts can be called upon using:
%D
%D \showsetup{\y!headtext}
%D \showsetup{\y!labeltext}
%D
%D The latter one has an upcased alternative \type{\LABELTEXT}.

\def\labellanguage{\currentmainlanguage}
\def\headlanguage {\currentmainlanguage}

\def\headtext%
  {\let\handletextprefix\firstoftwoarguments
   \dogetupsometextprefix\headlanguage\c!titel}

\def\leftlabeltext%
  {\let\handletextprefix\firstoftwoarguments
   \dogetupsometextprefix\labellanguage\c!label}

\def\rightlabeltext%
  {\let\handletextprefix\secondoftwoarguments
   \dogetupsometextprefix\labellanguage\c!label}

\def\DOLABELTEXT#1%
  {\bgroup
   \the\everyuppercase
   \dogetupsometextprefix\labellanguage\c!label{#1}% not \labeltext (see \MONTH)
   \egroup}

\def\LEFTLABELTEXT%
  {\def\handletextprefix##1##2{\uppercase{##1}}\DOLABELTEXT}

\def\RIGHTLABELTEXT%
  {\def\handletextprefix##1##2{\uppercase{##2}}\DOLABELTEXT}

\let\labeltext      \leftlabeltext
\let\LABELTEXT      \LEFTLABELTEXT
\def\labeltexts#1#2{\leftlabeltext{#1}#2\rightlabeltext{#1}}
\def\LABELTEXTS#1#2{\LEFTLABELTEXT{#1}#2\RIGHTLABELTEXT{#1}}

\def\dodogetupsometextprefix#1#2#3#4%
  {\doifdefinedelse{#2#1#3}
     {\getvalue{#2#1#3}}
     {\doifdefinedelse{#1#3}
        {\getvalue{#2#3}}
        {#4}}}

\newif\iflabeltextdone % needs to be reset elsewhere

\unexpanded\def\dogetupsometextprefix#1#2#3%
  {\global\labeltextdonetrue 
   \dodogetupsometextprefix{#1}{#2}{#3}
     {\dodogetupsometextprefix{\defaultlanguage{#1}}{#2}{#3}
        {\dodogetupsometextprefix{\s!en}{#2}{#3}
           {\dodogetupsometextprefix{\s!nl}{#2}{#3}
              {{\tttf[#2:~#3/#1]~}}}}}}

%D \macros
%D   {presetheadtext,presetlabeltext}
%D
%D The next two macros enable us to automatically define
%D head and label texts without replacing predefined ones.
%D This are internal macros.

\def\dopresetsometextprefix#1%
  {\def\dodocommando[##1][##2=##3]%
     {\doifundefined{##1##2}
        {\doassignsometextprefix[##1##2][##3,,]}}%
   \dodosetupsometextprefix{#1}}

\def\presetheadtext%
  {\dopresetsometextprefix\c!titel}

\def\presetlabeltext%
  {\dopresetsometextprefix\c!label}

%D \macros
%D   {translate}
%D
%D Sometismes macros contain language specific words that are to
%D be typeset. Such macros can be made (more) language
%D independant by using:
%D
%D \showsetup{\y!translate}
%D
%D like for instance:
%D
%D \starttypen
%D \translate[en=something,nl=iets]
%D \stoptypen
%D
%D which expands to {\em something} or {\em iets}, depending on
%D de current language.

\def\dotranslate[#1]% don't group! 
  {\getparameters[\??lg][#1]%
   \doifdefinedelse{\??lg\currentlanguage}%
     {\getvalue{\??lg\currentlanguage}}
     {\doifdefinedelse{\??lg\s!en}
        {\getvalue{\??lg\s!en}}
        {\doifdefinedelse{\??lg\s!nl}
          {\getvalue{\??lg\s!nl}}
          {[translation #1]}}}}

\unexpanded\def\translate%
  {\dosingleempty\dotranslate}

%D When used without argument, the last defined values are
%D used. This enables repetitive use like
%D
%D \starttypen
%D \en \translate\ means \nl \translate
%D \stoptypen

%D \macros
%D   {assigntranslation}
%D
%D This macro is a system macro, and can be used to assign a
%D translation to a macro. Its form is:
%D
%D \starttypen
%D \assigntranslation[en=something,nl=iets]\to\command
%D \stoptypen

\def\assigntranslation[#1]\to#2%
  {\getparameters[\??lg][#1]%
   \edef#2{\getvalue{\??lg\currentlanguage}}}

\protect

\endinput
