diff options
author | Michał Klichowicz <emkael@tlen.pl> | 2018-10-17 20:02:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-17 20:02:57 +0200 |
commit | 984540cd2dfba29c1dc9cbc43ab6fa4c85c7727b (patch) | |
tree | d03e49f564cec7c3eec7ce7c98fae530ec1544e0 /jfr_playoff/i18n.py | |
parent | 9a5f06ee9cddd38e11f49a2f934de202d34e63e2 (diff) | |
parent | 31fc51ce22e7c5197ed367cadd14d8a258f8fd65 (diff) |
Merge pull request #28 from emkael/develv1.2.0
v1.2
Diffstat (limited to 'jfr_playoff/i18n.py')
-rw-r--r-- | jfr_playoff/i18n.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/jfr_playoff/i18n.py b/jfr_playoff/i18n.py new file mode 100644 index 0000000..c4134a9 --- /dev/null +++ b/jfr_playoff/i18n.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import re + +from jfr_playoff.logger import PlayoffLogger + +PLAYOFF_I18N_DEFAULTS = { + 'SCORE': 'wynik', + 'FINAL_STANDINGS': 'klasyfikacja końcowa', + 'STANDINGS_PLACE': 'miejsce', + 'STANDINGS_TEAM': 'drużyna', + 'STANDINGS_CAPTIONS': 'legenda', + 'FOOTER_GENERATED': 'strona wygenerowana', + 'SWISS_DEFAULT_LABEL': 'Turniej o %d. miejsce' +} + +class PlayoffI18N(object): + + def __init__(self, settings): + self.settings = settings + self.string_match = re.compile(r'{{(.*)}}') + + def localize(self, string): + return re.sub( + self.string_match, + lambda x: self.__get_translation(x.group(1)), + string) + + def __get_translation(self, string): + for dictionary in [self.settings, PLAYOFF_I18N_DEFAULTS]: + if string in dictionary: + translation = dictionary[string].decode('utf8') + PlayoffLogger.get('i18n').info( + 'translation for %s: %s', string, translation) + return translation + PlayoffLogger.get('i18n').info( + 'translation for %s not found', string) + return '{{%s}}' % (string) |