%%
%% This is file `langselect.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% langselect.dtx  (with options: `pkg')
%% 
%% ========================================================================
%%  Package langselect - generate documents in different languages
%%                       from a common source. This is a generated file.
%% 
%%  (C) 2022-2026 Matthias Werner
%%  E-mail: matthias.werner@informatik.tu-chemnitz.de
%% 
%%  Released under the LaTeX Project Public License v1.3c or later
%%  See http://www.latex-project.org/lppl.txt
%% ========================================================================
%% 
\NeedsTeXFormat{LaTeX2e}[2022/06/01]
\def\packagename{langselect}
\ProvidesExplPackage{langselect}{2025/09/04}{v0.5.0}{support for different
  languages versions from a common source}
\seq_const_from_clist:cn{olsIsoTags}{aa,ab,ae,af,ak,am,an,ar,as,av,ay,az,ba,be,
  bg,bh,bi,bm,bn,bo,br,bs,ca,ce,ch,co,cr,cs,cu,cv,cy,da,de,dv,dz,ee,el,en,eo,es,
  et,eu,fa,ff,fi,fj,fo,fr,fy,ga,gd,gl,gn,gu,gv,ha,he,hi,ho,hr,ht,hu,hy,hz,ia,id,
  ie,ig,ii,ik,io,is,it,iu,ja,jv,ka,kg,ki,kj,kk,kl,km,kn,ko,kr,ks,ku,kv,kw,ky,la,
  lb,lg,li,ln,lo,lt,lu,lv,mg,mh,mi,mk,ml,mn,mr,ms,mt,my,na,nb,nd,ne,ng,nl,nn,no,
  nr,nv,ny,oc,oj,om,or,os,pa,pi,pl,ps,pt,qu,rm,rn,ro,ru,rw,sa,sc,sd,se,sg,si,sk,
  sl,sm,sn,so,sq,sr,ss,st,su,sv,sw,ta,te,tg,th,ti,tk,tl,tn,to,tr,ts,tt,tw,ty,ug,
  uk,ur,uz,ve,vi,vo,wa,wo,xh,yi,yo,za,zh,zu}

\newcommand\IfTagIsValidF[2]{%
  \seq_if_in:ceF{olsIsoTags}{#1}{#2}
}
\RequirePackage{varsfromjobname}[2025/08/03]
\newcommand\olsChangeCatEleven[1]{
  \def\tmpa{#1}
  \edef\tmpb{
    \noexpand\scantokens{
      \noexpand\edef\noexpand\olsCatElven{\tmpa}
    }
  }
  \tmpb
}
\cs_new:Npn \ols_use_map:n #1 {
  \cs_if_exist_use:cF { olslangmap / #1 }{ #1 }
}
\bool_new:N\ols_load_babel
\bool_new:N\ols_load_polyglossia
\DeclareKeys{
  languages.clist_gset:N = \ols_langs,
  languages.usage=load,
  targetlang.code = {
      \cs_if_exist:NF\olsTargetLanguage{
      \bool_if:nT{
        \str_if_eq_p:ee{\str_range:nnn{#1}{1}{3}}{job}
      }{%
        \olsChangeCatEleven{\getfromjobname{\str_range:Nnn{#1}{-1}{-1}}}
        \xdef\olsTargetLanguage{\olsCatElven}
      }
      \bool_if:nT{
        \str_if_eq_p:nn{#1}{babel} || \str_if_eq_p:nn{#1}{polyglossia}
      }{
        \str_if_empty:eF{\BCPdata{main.language}}{
          \edef\olsTargetLanguage{\BCPdata{main.language}}
        }
      }
      \str_if_eq:nnTF{#1}{meta}{
        \IfDocumentMetadataTF{
          \edef\tmpa{\GetDocumentProperty{document/lang}}
          \edef\tmpb{\str_range:Nnn\tmpa{1}{2}}
          \olsChangeCatEleven{\tmpb}
          \edef\olsTargetLanguage{\olsCatElven}
        }{
          \PackageWarningNoLine{\packagename}{No~meta~data~provided}
        }
      }
    }
    \cs_if_exist:NF \olsTargetLanguage {
      \edef\olsTargetLanguage{#1}
    }
  },
  targetlang.usage=load,
  prefix.store=\ols_sprefix,
  prefix.initial:n=l,
  prefix.usage=load,
  auto.bool_set:N=\ols_generate,
  auto.usage=load,
  auto.initial:n=true,
  trim.bool_set:N=\ols_trim,
  trim.usage=load,
  trim.initial:n=true,
  map.code:n = {
    \prop_new:N \ols_lang_pl
    \prop_clear:N \ols_lang_pl
    \prop_set_from_keyval:Nn \ols_lang_pl {#1}
    \prop_map_inline:Nn \ols_lang_pl
      { \cs_gset:cpn { olslangmap / \tl_to_str:n {##1} } {##2} }
    },
  load~babel .code:n = {
    \bool_set_true:N \ols_load_babel
    \PassOptionsToPackage{#1}{babel}
  },
  load~polyglossia .code:n = {
    \bool_set_true:N \ols_load_polyglossia
    \PassOptionsToPackage{#1}{polyglossia}
  },
  load.usage = load,
  unified~shorthands.bool_set:N=\ols_shorthands,
  unified~shorthands.initial:n=true,
  unified~shorthands.usage=load
}%
\ProcessKeyOptions\relax
\cs_if_exist:NF \olsTargetLanguage {
  \str_if_eq:eeF{\BCPdata{main.language}}{}{\edef\olsTargetLanguage{\BCPdata{main.language}}}
}
\cs_if_exist:NF \olsTargetLanguage {
  \IfDocumentMetadataT{
    \edef\tmpa{\GetDocumentProperty{document/lang}}
    \edef\tmpb{\str_range:Nnn\tmpa{1}{2}}
    \olsChangeCatEleven{\tmpb}
    \edef\olsTargetLanguage{\olsCatElven}
  }
}
\cs_if_exist:NF \olsTargetLanguage {
  \PackageWarningNoLine{\packagename}{Can't~identify~any~target~language.
    \MessageBreak Falling~back~to~'en'}
  \def\olsTargetLanguage{en}
}
\IfTagIsValidF{\olsTargetLanguage}{
  \PackageWarningNoLine{\packagename}{Do~not~recognize~language~'\olsTargetLanguage'.
    \MessageBreak Take~'en'~as~replacement}
  \def\olsTargetLanguage{en}
}
\int_compare:nNnT{\clist_count:N{\ols_langs}} < {2}{
  \PackageError{\packagename}{No~sufficient~number~of~selectable
    \MessageBreak~languages~provided}{
    You~have~to~provide~a~list~of~two~or~three\MessageBreak
    languages~via~'language'~option.}
  \aftergroup\endinput
}
\int_compare:nNnT{\clist_count:N\ols_langs} > {3}{
  \PackageWarningNoLine{\packagename}{Too~many~selectable~languages~provided.
    \MessageBreak I~will~ignore~the~superflous~languages}
}
\clist_map_inline:Nn\ols_langs {
  \IfTagIsValidF{#1}{
    \PackageError{\packagename}{Couldn't~resolve~selectable~language~'#1'}{
      Use~valid~ISO-639-1~code~in~option~'languages'.}
    \aftergroup\endinput
  }
}
\clist_if_in:NVF\ols_langs{\olsTargetLanguage}{
  \PackageError{\packagename}{Target~language~'\olsTargetLanguage'~is~not\MessageBreak
    in~the~list~of~selectable~languages}{
    Check~option~'language'~and~'targetlang'.}
}
\bool_if:nT{
  \ols_load_babel && \ols_load_polyglossia
}{
  \bool_set_false:N \ols_load_babel
  \bool_set_false:N \ols_load_polyglossia
  \PackageError{\packagename}{The~options~'load~babel'~and~'load~polyglossia'
    \MessageBreak are~mutual~exclusive,~you~can't~use~both}{Use~one~load~option,~only.}
}
\bool_if:nT{
  ( \cs_if_exist_p:c{ver@babel.sty} || \cs_if_exist_p:c{ver@polyglossia.sty} )
  &&
  ( \ols_load_babel && \ols_load_polyglossia )
}{
  \bool_set_false:N \ols_load_babel
  \bool_set_false:N \ols_load_polyglossia
  \PackageWarningNoLine{\packagename}{Can't~load~babel/polyglossia~for
    ~you,since\MessageBreak
    a~language~package~is~already~loaded.\MessageBreak
    I'll~ignore~that~option}
}
\edef\ols_mapped_target_lang{\ols_use_map:n{\olsTargetLanguage}}
\PackageNoteNoLine{\packagename}{Target~language~is~'\olsTargetLanguage'~(\ols_mapped_target_lang)}
\IfDocumentMetadataT{
  \edef\olsDocLang{\exp_args:Ne\str_range:nnn{\GetDocumentProperty{document/lang}}{1}{2}}
  \bool_if:nF{
    \str_if_eq_p:ee{\olsDocLang}{\olsTargetLanguage}
  }{
    \PackageWarningNoLine{\packagename}{Target~language~'\olsTargetLanguage'~
      doesn't~comply~with\MessageBreak \c_backslash_str
      DocumentMetadata~'\GetDocumentProperty{document/lang}'.\MessageBreak
      I'll~try~to~overwrite~the~meta~data}
    \DocumentMetadata{lang=\ols_mapped_target_lang}
  }
}
\NewHookWithArguments{langselect/language/before}{1}
\NewReversedHook{langselect/language/after}
\NewHookWithArguments{langselect/argument}{2}
\bool_new:c{ols_trilang}
\int_compare:nNnTF{\clist_count:N{\ols_langs}} > {2}{
  \bool_set_true:c{ols_trilang}
}{
  \bool_set_false:c{ols_trilang}
}
\def\olsFrstLanguage{\clist_item:Nn \ols_langs{1}}
\def\olsScndLanguage{\clist_item:Nn \ols_langs{2}}
\bool_if:cT{ols_trilang}{
  \def\olsThrdLanguage{\clist_item:Nn \ols_langs{3}}
}
\bool_if:NTF\ols_trim{
  \let\ols_trim:n=\tl_trim_spaces:n
}{
  \let\ols_trim:n=\relax
}
\NewDocumentCommand{\olsMakeBilangualMacro}{O{\ols_sprefix} m m o}{
  \str_if_eq:eeT{\olsTargetLanguage}{#2} {
    \IfValueTF{#4}{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#4}{s +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:n{\olsProcessArgs{##2}}
        }{
          \ols_trim:n{##2}
          \UseHook{langselect/language/after}
        }

      }
    }{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#2#3}{s +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:n{\olsProcessArgs{##2}}
        }{
          \ols_trim:n{##2}
          \UseHook{langselect/language/after}
        }
      }
    }
  }
  \str_if_eq:eeT{\olsTargetLanguage}{#3}{
    \IfValueTF{#4}{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#4}{s +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:n{\olsProcessArgs{##3}}
        }{
          \ols_trim:n{##3}
          \UseHook{langselect/language/after}
        }
      }
    }{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#2#3}{s +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:n{\olsProcessArgs{##3}}
        }{
          \ols_trim:n{##3}\UseHook{langselect/language/after}
        }
      }
    }
  }
}
\NewDocumentCommand{\olsMakeTrilangualMacro}{O{\ols_sprefix} m m m o}{
  \str_if_eq:eeT{\olsTargetLanguage}{#2} {
    \IfValueTF{#4}{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#5}{s +m +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##2}
          \UseHook{langselect/language/after}
        }
      }
    }{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#2#3#4}{s +m +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##2}
          \UseHook{langselect/language/after}
        }
      }
    }
  }
  \str_if_eq:eeT{\olsTargetLanguage}{#3} {
    \IfValueTF{#4}{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#5}{s +m +m +m}{
        \UseHook{langselect/language/before}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##3}
          \UseHook{langselect/language/after}
        }
      }
    }{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#2#3#4}{s +m +m +m}{
        \UseHook{langselect/language}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##3}
          \UseHook{langselect/language/after}
        }
      }
    }
  }
  \str_if_eq:eeT{\olsTargetLanguage}{#4} {
    \IfValueTF{#4}{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#5}{s +m +m +m}{
        \UseHook{langselect/language}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##4}
          \UseHook{langselect/language/after}
        }
      }
    }{
      \ExpandArgs{c}\NewExpandableDocumentCommand{#1#2#3#4}{s +m +m +m}{
        \UseHook{langselect/language}{\ols_mapped_target_lang}
        \IfBooleanTF{##1}{
          \ols_trim:{\olsProcessArgs{##2}}
        }{
          \ols_trim:{##4}
          \UseHook{langselect/language/after}
        }
      }
    }
  }
}
\bool_if:cTF{ols_generate}{
  \bool_if:cTF{ols_trilang}{
    \olsMakeTrilangualMacro{\olsFrstLanguage}{\olsScndLanguage}{\olsThrdLanguage}
  }{
    \olsMakeBilangualMacro{\olsFrstLanguage}{\olsScndLanguage}
  }
}{
  \PackageInfoNoLine{\packagename}{No~language~macros~generated.\MessageBreak
  Use~\string\olsMakeBilangualMacro~or~\string\olsMakeTrilangualMacro~to~generate.}
}

\seq_new:N \ols_args_seq
\int_new:N \ols_num_of_args
\tl_new:N \ols_format_str_tl

\makeatother
\NewDocumentCommand \olsProcessArgs { +m } {
  \tl_gset:Nn \ols_format_str_tl{#1\UseHook{langselect/language/after}}
  \int_zero:N \ols_num_of_args
  \int_step_inline:nnnn { 9 } { -1 } { 1 }
  {
    \regex_if_match:nnT {@##1}{ #1 }
    {
      \int_set:Nn \ols_num_of_args { ##1 } \prg_break:
    }
  }
  \int_compare:nNnTF {\ols_num_of_args} = { 0 }
  { #1 }{
    \seq_clear:N \ols_args_seq
    \ols_collect_replace:n \ols_num_of_args
  }
}
\cs_new_protected:Npn \ols_collect_replace:n #1 #2{
  \IfHookEmptyTF{langselect/argument}{
    \seq_put_right:Nn \ols_args_seq { #2 }
  }{
    \seq_put_right:Nn \ols_args_seq {
      \UseHook{langselect/argument}{\ols_mapped_target_lang}{#2}
    }
  }
  \int_compare:nNnTF { #1 } = { 1 }
  {
    \seq_map_indexed_inline:Nn \ols_args_seq
    {
      \tl_set:Nn \ols_replacement_tl { ##2 }

      \regex_replace_all:nnN
      { @##1 }
      { \u{ols_replacement_tl} }
      \ols_format_str_tl
    }
    \ols_format_str_tl
  }{
    \ols_collect_replace:n { \int_eval:n { #1 - 1 } }
  }
}
\makeatletter
\bool_if:NT \ols_load_babel{
  \RequirePackage[main=\ols_mapped_target_lang, provide*=*]{babel}
  \bool_if:nT{
    \ols_shorthands && !\str_if_eq_p:nn{olsTargetLanguage}{de}}
  {
    \languageshorthands{ngerman}
  }
}
\bool_if:NT\ols_load_polyglossia{
  \RequirePackage{polyglossia}
}
\cs_if_exist:cT{ver@babel.sty}{
  \AtBeginDocument{
    \selectlanguage{\ols_mapped_target_lang}
  }
}
\cs_if_exist:cT{ver@polyglossia.sty}{
  \bool_if:NTF\ols_shorthands{
   \setdefaultlanguage[babelshorthands=true]{\ols_mapped_target_lang}
  }{
    \setdefaultlanguage{\ols_mapped_target_lang}
  }
}
\bool_if:NT\ols_shorthands {
  \RequirePackage[autostyle=true]{csquotes}
  \AtBeginDocument{
    \cs_if_exist:cT{useshorthands}{
      \useshorthands*{"}
      \defineshorthand{"`}{\openautoquote}
      \defineshorthand{"'}{\closeautoquote}
      \defineshorthand{"/}{\textormath{\bbl@allowhyphens
          \discretionary{/}{}{/}\bbl@allowhyphens}{}}
    }
  }
}
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%%  Matthias Werner.
%%
%% End of file `langselect.sty'.

