diff --git a/filter_plugins/translate_yavdr.py b/filter_plugins/translate_yavdr.py index aea87e6..3eb535a 100644 --- a/filter_plugins/translate_yavdr.py +++ b/filter_plugins/translate_yavdr.py @@ -12,23 +12,18 @@ ANSIBLE_METADATA = { 'supported_by': 'yavdr' } - +import gettext from ansible.errors import AnsibleFilterError -from ansible.module_utils.six.moves.urllib.parse import urlsplit -from ansible.module_utils._text import to_text from ansible.utils import helpers -def translate_yavdr(text, language=None, **kwargs): - if language is None: - language = kwargs.get('system_language', 'en') - translation = kwargs.get('translations', {}).get(language, {}).get(text, None) - if translation: - return translation - else: +def translate_yavdr(text): + gettext.textdomain('yavdr') + try: + return gettext.gettext(text) + except: return text - # ---- Ansible filters ---- class FilterModule(object): ''' URI filter ''' diff --git a/group_vars/all b/group_vars/all index 3b26ff7..71a7a09 100644 --- a/group_vars/all +++ b/group_vars/all @@ -1,6 +1,9 @@ --- # file: group_vars/all +# for translation filter +locale: "{{ ansible_env.LANG }}" + # this is the standard text to put in templates ansible_managed_file: "*** YAVDR: ANSIBLE MANAGED FILE ***" branch: experimental