diff --git a/filter_plugins/translate_yavdr.py b/filter_plugins/translate_yavdr.py new file mode 100644 index 0000000..aea87e6 --- /dev/null +++ b/filter_plugins/translate_yavdr.py @@ -0,0 +1,39 @@ +# Copyright (c) 2017 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +ANSIBLE_METADATA = { + 'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'yavdr' +} + + +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: + return text + + +# ---- Ansible filters ---- +class FilterModule(object): + ''' URI filter ''' + + def filters(self): + return { + 'translate': translate_yavdr + }