-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Problemtools allows problem descriptions in multiple languages, but the fixed headlines are hard-coded in English like this:
| \newcommand{\sampleinputname}{Sample Input} |
It would be nice if those few headlines were localised, based on the two-letter language code of the problem description file.
One way I can think of doing that, implemented on https://github.com/thorehusfeldt/problemtools/tree/feat/i18n is to provide localisations in a yaml file in the template directory /problemtools/templates/latex/strings.yaml
.en:
sampleinputname: Sample Input
sampleoutputname: Sample Output
sampleinteractname: Sample Interaction
sampleinteractreadname: Read
sampleinteractwritename: Write
.sv:
sampleinputname: Exempel på indata
sampleoutputname: Exempel på utdata
sampleinteractname: Exempel på interaktion
sampleinteractreadname: Läs
sampleinteractwritename: SkrivThen /problemtools/templates/latex/template.tex gets a few new placeholders:
\renewcommand{\sampleinputname}{%(sampleinputname)s}
\renewcommand{\sampleoutputname}{%(sampleoutputname)s}
\renewcommand{\sampleinteractname}{%(sampleinteractname)s}
\renewcommand{\sampleinteractreadname}{%(sampleinteractreadname)s}
\renewcommand{\sampleinteractwritename}{%(sampleinteractwritename)s}and the templating mechanism in problemtools/template.py takes care of replacing strings into self.language, falling back on English.
if self.language in self.strings:
strings = self.strings[self.language]
else:
strings = self.strings['.en']
print('Unable to find string translations into {}, using English instead'.format(self.language))
for s in strings:
data[s] = strings[s]Other approaches exist, such as using templates in problemset.cls. Or using babel. But the above works, and is quite light-weight.