% \iffalse meta-comment
%
% File: siunitx-localization.dtx Copyright (C) 2020-2024,2026 Joseph Wright
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
% This file is part of the "siunitx bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% The released version of this bundle is available from CTAN.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/josephwright/siunitx
%
% for those people who are interested.
%
% -----------------------------------------------------------------------
%
%<*driver>
\documentclass{l3doc}
% Additional commands needed in this source
\ProvideDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
% The next line is needed so that \GetFileInfo will be able to pick up
% version data
\usepackage{siunitx}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{siunitx.sty}
%
% \title{^^A
%   \pkg{siunitx-localization} -- Localization^^A
%   \thanks{This file describes \fileversion,
%     last revised \filedate.}^^A
% }
%
% \author{^^A
%  Joseph Wright^^A
%  \thanks{^^A
%    E-mail:
%    \email{joseph@texdev.net}^^A
%   }^^A
% }
%
% \date{Released \filedate}
%
% \maketitle
%
% \begin{documentation}
%
% \section{Localization}
%
% This submodule is concerned with localization of \pkg{siunitx} output
% based on the locale. If the \pkg{translations} package is available, this
% is loaded here and used to provide various fixed strings for output.
%
% \begin{function}{locale}
%   \begin{syntax}
%     |locale| = \meta{locale}
%   \end{syntax}
%   Selects the \meta{locale} used to apply standard settings for other
%   keys, principally |exponent-product|, |inter-unit-product|
%   and |output-decimal-marker|.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{siunitx-localization} implementation}
%
% Start the \pkg{DocStrip} guards.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Identify the internal prefix.
%    \begin{macrocode}
%<@@=siunitx_locale>
%    \end{macrocode}
%
% Localization makes use of the \pkg{translations} package. This only happens
% if it is available, and is transparent to the user.
%    \begin{macrocode}
\file_if_exist:nT { translations.sty }
  {
    \RequirePackage { translations }
    \DeclareTranslation { Catalan }    { and } { i }
    \DeclareTranslation { Italian }    { and } { e }
    \DeclareTranslation { Portuguese } { and } { e }
    \DeclareTranslation { Slovene }    { and } { in }
    \DeclareTranslation { Italian }    { from~(numerical~range) } { da }
    \DeclareTranslation { Brazilian }  { to~(numerical~range) } { a }
    \DeclareTranslation { Catalan }    { to~(numerical~range) } { a }
    \DeclareTranslation { English }    { to~(numerical~range) } { to }
    \DeclareTranslation { French }     { to~(numerical~range) } { à }
    \DeclareTranslation { German }     { to~(numerical~range) } { bis }
    \DeclareTranslation { Italian }    { to~(numerical~range) } { a }
    \DeclareTranslation { Polish }     { to~(numerical~range) } { do }
    \DeclareTranslation { Portuguese } { to~(numerical~range) } { a }
    \DeclareTranslation { Slovene }    { to~(numerical~range) } { do }
    \DeclareTranslation { Spanish }    { to~(numerical~range) } { a }
    \keys_set:nn { siunitx }
      {
        list-final-separator =
          {
            \TextOrMath { \space } { \  }
            \text { \GetTranslation { and } }
            \TextOrMath { \space } { \ }
          } ,
        list-pair-separator =
          {
            \TextOrMath { \space } { \  }
            \text { \GetTranslation { and } }
            \TextOrMath { \space } { \  }
          } ,
        range-open-phrase =
          {
            \bool_lazy_or:nnF
              {
                \tl_if_blank_p:e
                  { \GetTranslation { from~(numerical~range) } }
              }
              {
                \str_if_eq_p:ee
                  { \GetTranslation { from~(numerical~range) } }
                  { from~(numerical~range) }
              }
              {
                \text { \GetTranslation { from~(numerical~range) } }
                \TextOrMath { \space } { \  }
              }
          } ,
        range-phrase =
          {
            \TextOrMath { \space } { \  }
            \text { \GetTranslation { to~(numerical~range) } }
            \TextOrMath { \space } { \  }
          }
      }
  }
%    \end{macrocode}
%
% \subsection{BPC-47 usage}
%
% \begin{macro}{\@@_setup:, \@@_setup_aux:}
% \begin{macro}{ \@@_setup:nnn}
% \begin{macro}{ \@@_setup:n}
%   If the output decimal marker is unchanged, it will be a letter. Under
%   those circumstances, check the BCP-47 data and then look up the appropriate
%   \pkg{babel} data file to see if we should adjust the setting. Only |.|
%   and |,| are supported.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_setup:
  {
    \bool_lazy_and:nnT
      { \str_if_eq_p:Vn \l_siunitx_number_output_decimal_tl { . } }
      {
        \tl_if_head_eq_catcode_p:VN
          \l_siunitx_number_output_decimal_tl A
      }
      { \@@_setup_aux: }
  }
\cs_new_protected:Npn \@@_setup_aux:
  {
    \exp_args:Neee \@@_setup:nnn
      { \BCPdata { language } }
      { \BCPdata { script } }
      { \BCPdata { region } }
  }
\cs_new_protected:Npn \@@_setup:nnn #1#2#3
  {
    \file_if_exist:nTF { babel- #1 - #2 - #3 .ini }
      { \@@_setup:n { babel- #1 - #2 - #3 .ini } }
      {
        \file_if_exist:nTF { babel- #1 - #2 .ini }
          { \@@_setup:n { babel- #2 - #3 .ini } }
          {
            \file_if_exist:nTF { babel- #1 - #3 .ini }
              { \@@_setup:n { babel- #1 - #3 .ini } }
              {
                \file_if_exist:nT { babel- #1 .ini }
                  { \@@_setup:n { babel- #1 .ini } }
              }
          }
      }
  }
\cs_new_protected:Npn \@@_setup:n #1
  {
    \ior_open:Nn \g_tmpa_ior {#1}
    \ior_str_map_inline:Nn \g_tmpa_ior
      {
        \str_if_eq:nnT {##1} { decimal~=~, }
          {
            \tl_set:Nn \l_siunitx_number_output_decimal_tl { , }
            \ior_map_break:
          }
      }
    \ior_close:N \g_tmpa_ior
  }
\IfTargetDateBefore { 2026-09-12 }
  { }
  { \AtBeginDocument { \@@_setup: } }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \end{implementation}
%
% \PrintIndex
