From 8d8e6af1783bf62ee6779f98fc30c3fd75ce955b Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 5 Jan 2017 13:23:53 +0100 Subject: Fetching translation strings and constants from tournament DB --- ausbutler/tour_config.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ausbutler/tour_config.py (limited to 'ausbutler/tour_config.py') 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() -- cgit v1.2.3