|
@@ -22,22 +22,11 @@ class FlaskBBDomain(Domain):
|
|
|
self.app = app
|
|
|
super(FlaskBBDomain, self).__init__()
|
|
|
|
|
|
- self.plugins_folder = os.path.join(
|
|
|
- os.path.join(self.app.root_path, "plugins")
|
|
|
- )
|
|
|
-
|
|
|
- # FlaskBB's translations
|
|
|
- self.flaskbb_translations = os.path.join(
|
|
|
- self.app.root_path, "translations"
|
|
|
- )
|
|
|
-
|
|
|
# Plugin translations
|
|
|
with self.app.app_context():
|
|
|
- self.plugin_translations = [
|
|
|
- os.path.join(plugin.path, "translations")
|
|
|
- for plugin in self.app.pluggy.get_plugins()
|
|
|
- if os.path.exists(os.path.join(plugin.path, "translations"))
|
|
|
- ]
|
|
|
+ self.plugin_translations = \
|
|
|
+ self.app.pluggy.hook.flaskbb_load_translations()
|
|
|
+ print(self.plugin_translations)
|
|
|
|
|
|
def get_translations(self):
|
|
|
"""Returns the correct gettext translations that should be used for
|
|
@@ -45,34 +34,18 @@ class FlaskBBDomain(Domain):
|
|
|
object if used outside of the request or if a translation cannot be
|
|
|
found.
|
|
|
"""
|
|
|
+ translations = super(FlaskBBDomain, self).get_translations()
|
|
|
locale = get_locale()
|
|
|
- cache = self.get_translations_cache()
|
|
|
-
|
|
|
- translations = cache.get(str(locale))
|
|
|
- if translations is None:
|
|
|
- # load flaskbb translations
|
|
|
- translations = babel.support.Translations.load(
|
|
|
- dirname=self.flaskbb_translations,
|
|
|
+ # now load and add the plugin translations
|
|
|
+ for plugin in self.plugin_translations:
|
|
|
+ plugin_translation = babel.support.Translations.load(
|
|
|
+ dirname=plugin,
|
|
|
locales=locale,
|
|
|
domain="messages"
|
|
|
)
|
|
|
+ translations.add(plugin_translation)
|
|
|
|
|
|
- # If no compiled translations are found, return the
|
|
|
- # NullTranslations object.
|
|
|
- if not isinstance(translations, babel.support.Translations):
|
|
|
- return translations
|
|
|
-
|
|
|
- # now load and add the plugin translations
|
|
|
- for plugin in self.plugin_translations:
|
|
|
- plugin_translation = babel.support.Translations.load(
|
|
|
- dirname=plugin,
|
|
|
- locales=locale,
|
|
|
- domain="messages"
|
|
|
- )
|
|
|
- translations.add(plugin_translation)
|
|
|
-
|
|
|
- cache[str(locale)] = translations
|
|
|
-
|
|
|
+ self.cache[str(locale)] = translations
|
|
|
return translations
|
|
|
|
|
|
|
|
@@ -91,7 +64,7 @@ def update_translations(include_plugins=False):
|
|
|
"-d", translations_folder])
|
|
|
|
|
|
if include_plugins:
|
|
|
- for plugin in current_app.pluggy.get_plugins():
|
|
|
+ for plugin in current_app.pluggy.list_name():
|
|
|
update_plugin_translations(plugin)
|
|
|
|
|
|
|
|
@@ -120,7 +93,7 @@ def compile_translations(include_plugins=False):
|
|
|
subprocess.call(["pybabel", "compile", "-d", translations_folder])
|
|
|
|
|
|
if include_plugins:
|
|
|
- for plugin in plugin_manager.all_plugins:
|
|
|
+ for plugin in current_app.pluggy.list_name():
|
|
|
compile_plugin_translations(plugin)
|
|
|
|
|
|
|
|
@@ -131,7 +104,7 @@ def add_plugin_translations(plugin, translation):
|
|
|
:param translation: The short name of the translation
|
|
|
like ``en`` or ``de_AT``.
|
|
|
"""
|
|
|
- plugin_folder = os.path.join(current_app.config["PLUGINS_FOLDER"], plugin)
|
|
|
+ plugin_folder = current_app.pluggy.get_plugin(plugin).__path__[0]
|
|
|
translations_folder = os.path.join(plugin_folder, "translations")
|
|
|
source_file = os.path.join(translations_folder, "messages.pot")
|
|
|
|
|
@@ -148,7 +121,7 @@ def update_plugin_translations(plugin):
|
|
|
|
|
|
:param plugin: The plugins identifier
|
|
|
"""
|
|
|
- plugin_folder = os.path.join(current_app.config["PLUGINS_FOLDER"], plugin)
|
|
|
+ plugin_folder = current_app.pluggy.get_plugin(plugin).__path__[0]
|
|
|
translations_folder = os.path.join(plugin_folder, "translations")
|
|
|
source_file = os.path.join(translations_folder, "messages.pot")
|
|
|
|
|
@@ -168,7 +141,7 @@ def compile_plugin_translations(plugin):
|
|
|
|
|
|
:param plugin: The plugins identifier
|
|
|
"""
|
|
|
- plugin_folder = os.path.join(current_app.config["PLUGINS_FOLDER"], plugin)
|
|
|
+ plugin_folder = current_app.pluggy.get_plugin(plugin).__path__[0]
|
|
|
translations_folder = os.path.join(plugin_folder, "translations")
|
|
|
|
|
|
if not os.path.exists(translations_folder):
|