diff options
author | emkael <emkael@tlen.pl> | 2017-01-05 13:23:53 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-01-05 13:23:53 +0100 |
commit | 8d8e6af1783bf62ee6779f98fc30c3fd75ce955b (patch) | |
tree | 9357afbafe7d196f360dede0f4996f859675776d | |
parent | 8a6b5981795fc65c994d8e42c78f23a6c8d10498 (diff) |
Fetching translation strings and constants from tournament DB
-rw-r--r-- | ausbutler/model.py | 12 | ||||
-rw-r--r-- | ausbutler/tour_config.py | 26 | ||||
-rw-r--r-- | config/logoh.json | 24 | ||||
-rw-r--r-- | config/translations.json | 2 |
4 files changed, 63 insertions, 1 deletions
diff --git a/ausbutler/model.py b/ausbutler/model.py index 6536b6a..fc088fa 100644 --- a/ausbutler/model.py +++ b/ausbutler/model.py @@ -1,7 +1,7 @@ from cached_property import cached_property from sqlalchemy import Column, MetaData, Table, func from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.types import Float, Integer +from sqlalchemy.types import Float, Integer, String from .db import get_session @@ -72,3 +72,13 @@ class Segment(Base): @cached_property def butler_count(self): return Segment.count_cache[(self.rnd, self.segment, self.tabl)] + +class Translation(Base): + __table__ = Table('logoh', MetaData(bind=session.bind), + Column('id', Integer, primary_key=True), + autoload=True) + +class Admin(Base): + __table__ = Table('admin', MetaData(bind=session.bind), + Column('shortname', String, primary_key=True), + autoload=True) diff --git a/ausbutler/tour_config.py b/ausbutler/tour_config.py new file mode 100644 index 0000000..43a8dc7 --- /dev/null +++ b/ausbutler/tour_config.py @@ -0,0 +1,26 @@ +from .config import load_config +from .db import get_session +from .model import Translation, Admin + +session = get_session() + +class Translations(object): + + translation_cache = { t.id: t.dane for t + in session.query(Translation).all() } + translation_mapping = load_config('logoh') + custom_translations = load_config('translations') + + @staticmethod + def get_translation(key): + if key in Translations.translation_mapping: + return Translations.translation_cache[Translations.translation_mapping[key]] + if key in Translations.custom_translations: + return Translations.custom_translations[key][Translations.detect_language()] + return '{{%s}}' % (key) + + @staticmethod + def detect_language(): + return 'en' if Translations.get_translation('ROUND').lower().strip() == 'round' else 'pl' + +Constants = session.query(Admin).one() diff --git a/config/logoh.json b/config/logoh.json new file mode 100644 index 0000000..a644c0a --- /dev/null +++ b/config/logoh.json @@ -0,0 +1,24 @@ +{ + "PAGE_TITLE": 0, + "INDIVIDUAL_CLASSIFICATION": 80, + "PLAYERS_WITHOUT_CHANCES": 90, + "PERCENT_NOT_LISTED": 92, + "PERCENT": 88, + "HEADER_PLACE": 65, + "HEADER_TEAM": 52, + "HEADER_IMPBRD": 44, + "HEADER_BOARDS": 50, + "HEADER_PREV_ROUNDS": 81, + "FOOTER_GENERATED": 11, + "FOOTER_OPTIMIZED": 15, + "ROUND": 18, + "SEGMENT": 8, + "HEADER_TABLE": 39, + "HEADER_IMPS": 14, + "HEADER_BOARD_NO": 64, + "FOOTER_ANALYSIS": 13, + "TABLE_CLOSED_NS": 101, + "TABLE_OPEN_NS": 99, + "TABLE_CLOSED_EW": 102, + "TABLE_OPEN_EW": 100 +} diff --git a/config/translations.json b/config/translations.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/config/translations.json @@ -0,0 +1,2 @@ +{ +} |