mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add m18n helper to check that a key exist
This commit is contained in:
parent
bdd048197d
commit
cde45de0ba
1 changed files with 12 additions and 0 deletions
|
@ -86,6 +86,9 @@ class Translator(object):
|
||||||
self.locale = locale
|
self.locale = locale
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def key_exists(self, key):
|
||||||
|
return key in self._translations[self.default_locale]
|
||||||
|
|
||||||
def translate(self, key, *args, **kwargs):
|
def translate(self, key, *args, **kwargs):
|
||||||
"""Retrieve proper translation for a key
|
"""Retrieve proper translation for a key
|
||||||
|
|
||||||
|
@ -258,6 +261,15 @@ class Moulinette18n(object):
|
||||||
"""
|
"""
|
||||||
return self._namespaces[self._current_namespace].translate(key, *args, **kwargs)
|
return self._namespaces[self._current_namespace].translate(key, *args, **kwargs)
|
||||||
|
|
||||||
|
def key_exists(self, key):
|
||||||
|
"""Check if a key exists in the translation files
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
- key -- The key to translate
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self._namespaces[self._current_namespace].key_exists(key)
|
||||||
|
|
||||||
|
|
||||||
class MoulinetteSignals(object):
|
class MoulinetteSignals(object):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue