[Tex/LaTex] Glossaries acronyms two languages

acronymsglossarieslanguages

I'm using glossaries package to make my list of acronyms. I'm writing in Spanish but some of my acronyms are in English. I want them to be displayed like:
Spanish description – English long (Short) –

I was thinking on using the description label in glossaries to include the Spanish description. However I don't know how to modify the \acX macros in order to display the acronym correctly (first time all, next just the short, etc.)

Any help or hint is more than welcome.

CU

Edit: After having Using the glossaries package for English acronyms in German documents I need it to be modified to a format like:

OtherLanguage_long (Short, Long)
Long (Short)

ie. –> Calidad de Servicio (QoS, Quality of Service)
Internet Protocol (IP)

Edit 2: Problem solved… At least I think so.
I've created to tokens, one for plural and another for singular.

\documentclass{article}

\usepackage[acronym, toc, shortcuts]{glossaries}
\usepackage{etoolbox}

\newtoks\customtoksingular
\newtoks\customtokplural

\renewcommand*{\newacronymhook}{%
 \edef\dosetkeys{\noexpand\setkeys{glossentry}{user1={},\the\glskeylisttok}}%
 \dosetkeys
 \ifcsempty{@glo@useri}%
 {%
   %\expandafter\customtoksingular\expandafter{\the\glsshorttok\space(\the\glslongtok)}%
   \expandafter\customtoksingular\expandafter{\noexpand\acrfullformat{\the\glslongtok}{\the\glsshorttok}}%
 }%
 {%
   \edef\custom{\csexpandonce{@glo@useri}\space(\the\glsshorttok, \the\glslongtok)}%
   \expandafter\customtoksingular\expandafter{\custom}%
 }%
 \ifcsempty{@glo@userii}%
 {%
   %\expandafter\customtoksingular\expandafter{\the\glsshorttok\space(\the\glslongtok)}%
   \expandafter\customtokplural\expandafter{\noexpand\acrfullformat
           {\noexpand\glsentrylongpl{\the\glslabeltok}}%
           {\noexpand\glsentryshortpl{\the\glslabeltok}}}
 }%
 {%
   \edef\custom{\csexpandonce{@glo@userii}\space(\the\glsshorttok, \the\glslongtok\noexpand\acrpluralsuffix)}%
   \expandafter\customtokplural\expandafter{\custom}%
 }%
}

\newcommand*{\custompostdesc}[1]{%
  \ifcsempty{glo@#1@useri}{}{ (\glsentryuseri{#1})}%
}

\renewcommand*{\CustomAcronymFields}{%
  user1={},%
  name={\the\glsshorttok},%
  description={\the\glslongtok\noexpand\custompostdesc{\the\glslabeltok}},%
  first={\the\customtoksingular},%
  firstplural={\the\customtokplural},%
  % first={\the\glslongtok\space(\the\customtoksingular)},%
  %firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space (the\customtoksingular},%
  text={\the\glsshorttok},%
  plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}

\SetCustomStyle

\makeglossaries

\newacronym[user1=interfaz de programaci\'{o}n de la aplicaci\'{o}n, user2=interfaces de programaci\'{o}n de la aplicaci\'{o}n]{api}{API}{Application Programming Interface}
\newacronym{aa}{AA}{Another Acronym}

\begin{document}

First use: Las \acp{api} ....  Subsequent use: \acp{api}

\glsresetall{}

First use: Las \ac{api} ....  Subsequent use: \ac{api}

First use: \gls{aa}. Subsequent use: \gls{aa}.

\printglossary[type=\acronymtype]

\end{document}

Best Answer

I recommend you upgrade to the latest version of glossaries (v4.01 at time of writing) as it's more flexible. Here's an example that uses v4.01:

\documentclass[spanish,english]{article}

\usepackage{babel}
\usepackage{etoolbox}
\usepackage[acronym,toc,shortcuts]{glossaries}

\makeglossaries

% Add new key for long Spanish form:
\glsaddkey
{longsp}% key
{}% default value
{\glsentrylongsp}% new command analogous to \glsentrylong
{\Glsentrylongsp}% new command analogous to \Glsentrylong
{\acrlongsp}% new command analogous to \acrlong
{\Acrlongsp}% new command analogous to \Acrlong
{\ACRlongsp}% new command analogous to \ACRlong

% Add new key for plural long Spanish form:
\glsaddkey
{longplsp}% key
{}% default value
{\glsentrylongplsp}% new command analogous to \glsentrylongpl
{\Glsentrylongplsp}% new command analogous to \Glsentrylongpl
{\acrlongplsp}% new command analogous to \acrlongpl
{\Acrlongplsp}% new command analogous to \Acrlongpl
{\ACRlongplsp}% new command analogous to \ACRlongpl

% Provide conditional to test if longsp/longplsp has been set
\newcommand*{\glsifhaslongsp}[3]{%
  \ifcsempty{glo@#1@longsp}{#3}{#2}%
}
\newcommand*{\glsifhaslongplsp}[3]{%
  \ifcsempty{glo@#1@longplsp}{#3}{#2}%
}

% Set up custom acronym style:
\renewcommand*{\CustomAcronymFields}{%
  name={\the\glsshorttok},
  description={\the\glslongtok},%
}

% Set the display style for acronyms (used by commands like \gls, \glspl, \ac, \acp or \glsdisp)
\renewcommand*\SetCustomDisplayStyle[1]{%
  \defglsentryfmt[#1]{%
    \ifdefempty\glscustomtext
    {% \glsdisp not used
      \ifglsused\glslabel
      {% subsequent use
         \glsifplural
         {% plural
           \glscapscase
           {% subsequent, plural, no case change
             \glsentryshortpl{\glslabel}\glsinsert%
           }%
           {% subsequent, plural, first letter upper case
             \Glsentryshortpl{\glslabel}\glsinsert%
           }%
           {% subsequent, plural, all caps
             \MakeTextUppercase{\glsentryshortpl{\glslabel}\glsinsert}%
           }%
         }%
         {% singular
           \glscapscase
           {% subsequent, singular, no case change
             \glsentryshort{\glslabel}\glsinsert%
           }%
           {% subsequent, singular, first letter upper case
             \Glsentryshort{\glslabel}\glsinsert%
           }%
           {% subsequent, singular, all caps
             \MakeTextUppercase{\glsentryshort{\glslabel}\glsinsert}%
           }%
         }%
      }%
      {% first use
         \glsifplural
         {% plural
           \glsifhaslongplsp\glslabel
           {% first use, plural, has Spanish long form
             \glscapscase
             {% first use, plural, Spanish, no case change
               \glsentrylongplsp{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel},\space
                \glsentrylongpl{\glslabel})%
             }%
             {% first use, plural, Spanish, first letter upper case
               \Glsentrylongplsp{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel},\space
                \glsentrylongpl{\glslabel})%
             }%
             {% first use, plural, Spanish, all caps
               \MakeTextUppercase{\glsentrylongplsp{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel},\space
                \glsentrylongpl{\glslabel})}%
             }%
           }%
           {% first use, plural, doesn't have Spanish long form
             \glscapscase
             {% first use, plural, no Spanish, no case change
               \glsentrylongpl{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel})%
             }%
             {% first use, plural, no Spanish, first letter upper case
               \Glsentrylongpl{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel})%
             }%
             {% first use, plural, no Spanish, all caps
               \MakeTextUppercase{\glsentrylongpl{\glslabel}\glsinsert\space
               (\glsentryshortpl{\glslabel})}%
             }%
           }%
         }%
         {% singular
           \glsifhaslongsp\glslabel
           {% first use, singular, has Spanish long form
             \glscapscase
             {% first use, singular, Spanish, no case change
               \glsentrylongsp{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel},\space
                \glsentrylong{\glslabel})%
             }%
             {% first use, singular, Spanish, first letter upper case
               \Glsentrylongsp{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel},\space
                \glsentrylong{\glslabel})%
             }%
             {% first use, singular, Spanish, all caps
               \MakeTextUppercase{\glsentrylongsp{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel},\space
                \glsentrylong{\glslabel})}%
             }%
           }%
           {% first use, singular, doesn't have Spanish long form
             \glscapscase
             {% first use, singular, no Spanish, no case change
               \glsentrylong{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel})%
             }%
             {% first use, singular, no Spanish, first letter upper case
               \Glsentrylong{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel})%
             }%
             {% first use, singular, no Spanish, all caps
               \MakeTextUppercase{\glsentrylong{\glslabel}\glsinsert\space
               (\glsentryshort{\glslabel})}%
             }%
           }%
         }%
      }%
    }%
    {% \glsdisp used
      \glscustomtext
    }%
  }%
}

\SetCustomStyle

% Define a new glossary style that checks for the existence of
% the longsp field.
\newglossarystyle{listsp}{%
  \setglossarystyle{list}% base style on the list style
  \renewcommand*{\glossentry}[2]{%
  \item[\glsentryitem{##1}%
        \glstarget{##1}{\glossentryname{##1}}]
    \glossentrydesc{##1}%
    \glsifhaslongsp{##1}{\space(\glsentrylongsp{##1})}{}%
    \glspostdescription\space ##2}%
}

\newacronym
 [longsp=interfaz de programaci\'{o}n de la aplicaci\'{o}n,
  longplsp=interfaces de programaci\'{o}n de la aplicaci\'{o}n
 ]{api}{API}{Application Programming Interface}

\newacronym{aa}{AA}{Another Acronym}

\begin{document}

First use: Las \acp{api} ....  Subsequent use: \acp{api}

\glsresetall

First use: Las \ac{api} ....  Subsequent use: \ac{api}

First use: \gls{aa}. Subsequent use: \gls{aa}.

\printglossary[type=\acronymtype,style=listsp]

\end{document}

This produces:

Image of resulting document

Edit:

If you upgrade to the latest version (v4.02, 2013/12/05) it's easier to define a new acronym style and have \acf match the style. (Although it's also possible to define acronym styles where they don't match, as is the case with the predefined footnote style where \acr doesn't use a footnote.) Here's the above example rewritten using v4.02 code:

\documentclass[spanish,english]{article}

\usepackage{babel}
\usepackage{etoolbox}
\usepackage[acronym,toc,shortcuts]{glossaries}

\makeglossaries

% Add new key for long Spanish form:
\glsaddkey
{longsp}% key
{}% default value
{\glsentrylongsp}% new command analogous to \glsentrylong
{\Glsentrylongsp}% new command analogous to \Glsentrylong
{\acrlongsp}% new command analogous to \acrlong
{\Acrlongsp}% new command analogous to \Acrlong
{\ACRlongsp}% new command analogous to \ACRlong

% Add new key for plural long Spanish form:
\glsaddkey
{longplsp}% key
{}% default value
{\glsentrylongplsp}% new command analogous to \glsentrylongpl
{\Glsentrylongplsp}% new command analogous to \Glsentrylongpl
{\acrlongplsp}% new command analogous to \acrlongpl
{\Acrlongplsp}% new command analogous to \Acrlongpl
{\ACRlongplsp}% new command analogous to \ACRlongpl

% Provide conditional to test if longsp/longplsp has been set
\newcommand*{\glsifhaslongsp}[3]{%
  \ifcsempty{glo@#1@longsp}{#3}{#2}%
}
\newcommand*{\glsifhaslongplsp}[3]{%
  \ifcsempty{glo@#1@longplsp}{#3}{#2}%
}

% Define new acronym style:

\newacronymstyle{spanish}
{% base the display style on 'long-short'
  \GlsUseAcrEntryDispStyle{long-short}%
}%
{% base the definitions on 'long-short'
  \GlsUseAcrStyleDefs{long-short}%  
% Make some custom modifications for the first use display.
% Singular, no case change:
  \renewcommand*{\genacrfullformat}[2]{%
   \glsifhaslongsp{##1}%
   {% has Spanish version:
      \glsentrylongsp{##1}##2\space
      (\firstacronymfont{\glsentryshort{##1}}, \glsentrylong{##1})%
   }%
   {%
     \glsentrylong{##1}##2\space
     (\firstacronymfont{\glsentryshort{##1}})%
   }%
  }%
% Singular, first letter upper case:
  \renewcommand*{\Genacrfullformat}[2]{%
   \glsifhaslongsp{##1}%
   {% has Spanish version:
      \Glsentrylongsp{##1}##2\space
      (\firstacronymfont{\glsentryshort{##1}}, \glsentrylong{##1})%
   }%
   {%
     \Glsentrylong{##1}##2\space
     (\firstacronymfont{\glsentryshort{##1}})%
   }%
  }%
% Plural, no case change:
  \renewcommand*{\genplacrfullformat}[2]{%
   \glsifhaslongplsp{##1}%
   {% has Spanish version:
      \glsentrylongplsp{##1}##2\space
      (\firstacronymfont{\glsentryshortpl{##1}}, \glsentrylongpl{##1})%
   }%
   {%
     \glsentrylongpl{##1}##2\space
     (\firstacronymfont{\glsentryshortpl{##1}})%
   }%
  }%
% Plural, first letter upper case:
  \renewcommand*{\Genplacrfullformat}[2]{%
    \glsifhaslongplsp{##1}%
    {% has Spanish version:
      \Glsentrylongplsp{##1}##2\space
      (\firstacronymfont{\glsentryshortpl{##1}}, \glsentrylongpl{##1})%
    }%
    {%
      \Glsentrylongpl{##1}##2\space
      (\firstacronymfont{\glsentryshortpl{##1}})%
    }%
  }%
}

% switch to the new style:
\setacronymstyle{spanish}

% Define a new glossary style that checks for the existence of
% the longsp field.
\newglossarystyle{listsp}{%
  \setglossarystyle{list}% base style on the list style
  \renewcommand*{\glossentry}[2]{%
  \item[\glsentryitem{##1}%
        \glstarget{##1}{\glossentryname{##1}}]
    \glossentrydesc{##1}%
    \glsifhaslongsp{##1}{\space(\glsentrylongsp{##1})}{}%
    \glspostdescription\space ##2}%
}

\newacronym
 [longsp=interfaz de programaci\'{o}n de la aplicaci\'{o}n,
  longplsp=interfaces de programaci\'{o}n de la aplicaci\'{o}n
 ]{api}{API}{Application Programming Interface}

\newacronym{aa}{AA}{Another Acronym}

\begin{document}

First use: Las \acp{api} ....  Subsequent use: \acp{api}

\glsresetall

First use: Las \ac{api} ....  Subsequent use: \ac{api}

First use: \gls{aa}. Subsequent use: \gls{aa}.

Full form: \acf{api}, \acf{aa}.

\printglossary[type=\acronymtype,style=listsp]

\end{document}

This produces:

Image of resulting document

Edit 2:

In answer to @cacamailg's comment regarding only using the non-English version, the simplest method is just to define a set of commands that check the first use flag like this:

\newcommand*{\acfor}[2][]{%
 \ifglsused{#2}%
 {\acrshort[#1]{#2}}%
 {\acrlongsp[#1]{#2} (\acrshort[#1]{#2})\glsunset{#2}}%
}

\newcommand*{\Acfor}[2][]{%
 \ifglsused{#2}%
 {\Acrshort[#1]{#2}}%
 {\Acrlongsp[#1]{#2} (\acrshort[#1]{#2})\glsunset{#2}}%
}

\newcommand*{\acplfor}[2][]{%
 \ifglsused{#2}%
 {\acrplshort[#1]{#2}}%
 {\acrlongplsp[#1]{#2} (\acrshortpl[#1]{#2})\glsunset{#2}}%
}

\newcommand*{\Acplfor}[2][]{%
 \ifglsused{#2}%
 {\Acrshortpl[#1]{#2}}%
 {\Acrlongplsp[#1]{#2} (\acrshortpl[#1]{#2})\glsunset{#2}}%
}

Then you can do something like:

\acfor{api}. Next use: \acfor{api}.

This has some limitations, for example, you can't use the final insert optional argument used by commands like \gls.