From 14369452395b7cda932ba06e483c8cfd7556fb62 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 20 Apr 2013 23:24:11 +0000 Subject: [PATCH] [r22039]Bug 6533: Report plugin name when failing to load an add-on translation Message now says (e.g.) WARNING: Plugin ExtendedAttributes has no translation for any of your configured languages, using US English instead svn: r22056 --- gramps/gen/plug/_pluginreg.py | 9 ++++++++- gramps/gen/utils/grampslocale.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 1ff59218a..f748ca8b5 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -1090,7 +1090,14 @@ class PluginRegister(object): fd.close() if os.path.exists(os.path.join(os.path.dirname(full_filename), 'locale')): - local_gettext = glocale.get_addon_translator(full_filename).gettext + try: + local_gettext = glocale.get_addon_translator(full_filename).gettext + except ValueError: + print(_('WARNING: Plugin %(plugin_name)s has no translation' + ' for any of your configured languages, using US' + ' English instead') % + {'plugin_name' : filename.split('.')[0] }) + local_gettext = glocale.translation.gettext else: local_gettext = glocale.translation.gettext try: diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index c47e73efe..3e997b691 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -535,8 +535,15 @@ class GrampsLocale(object): LOG.warning("Unable to create collator: %s", str(err)) self.collator = None - self.translation = self._get_translation(self.localedomain, - self.localedir, self.language) + try: + self.translation = self._get_translation(self.localedomain, + self.localedir, + self.language) + except ValueError: + LOG.warning("Unable to find translation for languages in %s, using US English", ':'.join(self.language)) + self.translation = GrampsNullTranslations() + self.translation._language = "en" + # This is a no-op for secondaries but needs the translation # set, so it needs to be here. self._set_dictionaries() @@ -578,7 +585,8 @@ class GrampsLocale(object): if not languages or len(languages) == 0: LOG.warning("No language provided, using US English") else: - LOG.warning("No usable languages found in %s for %s, using US English", ':'.join(languages), os.path.abspath(localedir)) + raise ValueError("No usable translations in %s" % + ':'.join(languages)) translator = GrampsNullTranslations() translator._language = "en" return translator