summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-05-01 13:44:35 +0200
committeremkael <emkael@tlen.pl>2018-05-01 13:44:35 +0200
commit24a151f45b5104471a1a07e2a5aa72066cba3be9 (patch)
tree8e575e99bc9d4576f64a024ba636b2097b5f41dc /jfr_playoff
parent72c30e7b12a75d43b64e31094bf3f9d3a899fe65 (diff)
Internationalization and localization of strings
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/i18n.py31
-rw-r--r--jfr_playoff/template.py21
2 files changed, 43 insertions, 9 deletions
diff --git a/jfr_playoff/i18n.py b/jfr_playoff/i18n.py
new file mode 100644
index 0000000..0caa107
--- /dev/null
+++ b/jfr_playoff/i18n.py
@@ -0,0 +1,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&nbsp;%d.&nbsp;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 string
diff --git a/jfr_playoff/template.py b/jfr_playoff/template.py
index 5fd0c45..70c179b 100644
--- a/jfr_playoff/template.py
+++ b/jfr_playoff/template.py
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
+from jfr_playoff.i18n import PlayoffI18N
+
class PlayoffTemplateStrings(object):
MATCH_TABLE = '''
<table border="0" cellspacing="0">
<tr>
<td class="s12" width="%d">&nbsp;</td>
- <td class="bdcc2" width="%d">&nbsp;wynik&nbsp;</td>
+ <td class="bdcc2" width="%d">&nbsp;{{SCORE}}&nbsp;</td>
</tr>
%s
</table>
@@ -84,14 +86,14 @@ class PlayoffTemplateStrings(object):
LEADERBOARD = '''
<table border="0" cellspacing="0">
<tr>
- <td class="bdnl12" colspan="2" align="center" style="text-transform: uppercase"><b>&nbsp;KLASYFIKACJA KOŃCOWA&nbsp;</b></td>
+ <td class="bdnl12" colspan="2" align="center" style="text-transform: uppercase"><b>&nbsp;{{FINAL_STANDINGS}}&nbsp;</b></td>
</tr>
<tr>
<td class="e" colspan="2">&nbsp;</td>
</tr>
<tr>
- <td class="bdcc12">&nbsp;miejsce&nbsp;</td>
- <td class="bdcc2">&nbsp;drużyna&nbsp;</td>
+ <td class="bdcc12">&nbsp;{{STANDINGS_PLACE}}&nbsp;</td>
+ <td class="bdcc2">&nbsp;{{STANDINGS_TEAM}}&nbsp;</td>
</tr>
%s
</table>
@@ -113,7 +115,7 @@ class PlayoffTemplateStrings(object):
LEADERBOARD_CAPTION_TABLE = '''
<table class="caption_table" border="0" cellspacing="0">
<tr><td class="e">&nbsp;</td></tr>
- <tr><td class="bdnl12" align="center" style="text-transform: uppercase"><b>&nbsp;LEGENDA&nbsp;</b></td></tr>
+ <tr><td class="bdnl12" align="center" style="text-transform: uppercase"><b>&nbsp;{{STANDINGS_CAPTIONS}}&nbsp;</b></td></tr>
%s
</table>
'''
@@ -156,7 +158,7 @@ class PlayoffTemplateStrings(object):
'''
PAGE_BODY_FOOTER = '''
- <p class="f">&nbsp;Admin&nbsp;&copy;Jan Romański&#39;2005, PlayOff&nbsp;&copyMichał Klichowicz&#39;2017-2018, strona wygenerowana %s</p>
+ <p class="f">&nbsp;Admin&nbsp;&copy;Jan Romański&#39;2005, PlayOff&nbsp;&copyMichał Klichowicz&#39;2017-2018, {{FOOTER_GENERATED}} %s</p>
'''
PAGE = '''
@@ -179,12 +181,13 @@ class PlayoffTemplateStrings(object):
[<a href="%s" class="zb" target="_top">&nbsp;<img src="images/A.gif" />&nbsp;%s&nbsp;<img src="images/A.gif" />&nbsp;</a>]<br /><br />
'''
- SWISS_DEFAULT_LABEL = 'Turniej o&nbsp;%d.&nbsp;miejsce'
+ SWISS_DEFAULT_LABEL = '{{SWISS_DEFAULT_LABEL}}'
class PlayoffTemplate(object):
def __init__(self, settings):
- self.settings = settings
+ self.i18n = PlayoffI18N(settings)
def get(self, string, *params):
- return getattr(PlayoffTemplateStrings, string).decode('utf8') % params
+ return self.i18n.localize(
+ getattr(PlayoffTemplateStrings, string).decode('utf8')) % params