add translation filter

This commit is contained in:
Alexander Grothe 2017-12-18 11:40:33 +01:00
parent 89963fa35b
commit 767807e3e4
1 changed files with 39 additions and 0 deletions

View File

@ -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
}