Add m18n helper to check that a key exist

This commit is contained in:
Alexandre Aubin 2021-02-28 16:54:19 +01:00
parent bdd048197d
commit cde45de0ba

View file

@ -86,6 +86,9 @@ class Translator(object):
self.locale = locale
return True
def key_exists(self, key):
return key in self._translations[self.default_locale]
def translate(self, key, *args, **kwargs):
"""Retrieve proper translation for a key
@ -258,6 +261,15 @@ class Moulinette18n(object):
"""
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):