I am writing a multi-language document in latex.
I am using siunitx package in conjonction with babel to handle every numerical and units related numeric values.
My goal was to declare a new unit (for instance \fps) which would output differently depending on the locale selected.
I was thus thinking of something like this :
\documentclass[french,english]{book}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{siunitx}
\sisetup{range-units = single}
\addto\extrasfrench{%
\sisetup{locale = FR, group-separator = {\,}, detect-all}%
\DeclareSIUnit[number-unit-product = \text{~}]{\fps}{images\text{~}par\text{~}seconde}}
\addto\extrasenglish{\sisetup{locale = US, group-separator = {,}, detect-all}%
\DeclareSIUnit[number-unit-product = \text{~}]{\fps}{frames\text{~}per\text{~}second}}
\begin{document}
English: \SIrange{5}{6}{\fps}
\begin{otherlanguage}{french}
Français: \SIrange{5}{6}{\fps}
\end{otherlanguage}
\end{document}
Unfortunately this idea cannot work since the
\DeclareSIUnit[number-unit-product = \text{~}]{\fps}{frames\text{~}per\text{~}second}
macro is then executed within the document and thus resulting in an error ?
Any idea ?
Thank you.
Best Answer
You can use the facilities of the
translator
package to do this. If the package is in your system, thensiunitx
loads it automatically. You can then set up the unit withand declare translations with
In your document this gives