summaryrefslogtreecommitdiff
path: root/jfr_playoff/i18n.py
blob: e22a5634790b928aaa1401b8fb60cb5234b15e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-

import re

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:
                return dictionary[string].decode('utf8')
        return '{{%s}}' % (string)