mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[mod] during tests failed to translate string is an error
This commit is contained in:
parent
fdf9a719f1
commit
2403ee1b7d
2 changed files with 21 additions and 4 deletions
|
@ -15,6 +15,10 @@ from moulinette.cache import get_cachedir
|
|||
logger = logging.getLogger('moulinette.core')
|
||||
|
||||
|
||||
def during_unittests_run():
|
||||
return "TESTS_RUN" in os.environ
|
||||
|
||||
|
||||
# Internationalization -------------------------------------------------
|
||||
|
||||
class Translator(object):
|
||||
|
@ -97,7 +101,10 @@ class Translator(object):
|
|||
key, unformatted_string, args, kwargs, e.__class__.__name__, e
|
||||
)
|
||||
|
||||
logger.exception(error_message)
|
||||
if not during_unittests_run():
|
||||
logger.exception(error_message)
|
||||
else:
|
||||
raise Exception(error_message)
|
||||
|
||||
failed_to_format = True
|
||||
|
||||
|
@ -112,11 +119,20 @@ class Translator(object):
|
|||
error_message = "Failed to format translatable string '%s': '%s' with arguments '%s' and '%s', raising error: %s(%s) (don't panic this is just a warning)" % (
|
||||
key, unformatted_string, args, kwargs, e.__class__.__name__, e
|
||||
)
|
||||
logger.exception(error_message)
|
||||
if not during_unittests_run():
|
||||
logger.exception(error_message)
|
||||
else:
|
||||
raise Exception(error_message)
|
||||
|
||||
return self._translations[self.locale][key].encode('utf-8')
|
||||
|
||||
logger.exception("unable to retrieve string to translate with key '%s' for default locale 'locales/%s.json' file (don't panic this is just a warning)",
|
||||
key, self.default_locale)
|
||||
error_message = "unable to retrieve string to translate with key '%s' for default locale 'locales/%s.json' file (don't panic this is just a warning)" % key, self.default_locale
|
||||
|
||||
if not during_unittests_run():
|
||||
logger.exception(error_message)
|
||||
else:
|
||||
raise Exception(error_message)
|
||||
|
||||
return key
|
||||
|
||||
def _load_translations(self, locale, overwrite=False):
|
||||
|
|
|
@ -4,3 +4,4 @@ norecursedirs = dist doc build .tox .eggs
|
|||
testpaths = test/
|
||||
env =
|
||||
MOULINETTE_LOCALES_DIR = {PWD}/locales
|
||||
TESTS_RUN = True
|
||||
|
|
Loading…
Add table
Reference in a new issue