l10n.py 566 Bytes
Newer Older
Lukas Fleischer's avatar
Lukas Fleischer committed
1
2
import gettext

3
4
import aurweb.config

Lukas Fleischer's avatar
Lukas Fleischer committed
5
6
7

class Translator:
    def __init__(self):
8
        self._localedir = aurweb.config.get('options', 'localedir')
Lukas Fleischer's avatar
Lukas Fleischer committed
9
10
11
12
13
14
        self._translator = {}

    def translate(self, s, lang):
        if lang == 'en':
            return s
        if lang not in self._translator:
15
            self._translator[lang] = gettext.translation("aurweb",
16
                                                         self._localedir,
Lukas Fleischer's avatar
Lukas Fleischer committed
17
                                                         languages=[lang])
18
        return self._translator[lang].gettext(s)