mirror of
https://github.com/RustyRaptor/flaskbb.git
synced 2026-12-03 15:35:21 -07:00
Better options for the translation commands
This commit is contained in:
1 parent
c90f281b02
commit
42ca53679d
4 files changed
+75
-31
No files matched your search
+2
-1
@@ -7,9 +7,10 @@ python:
|
||||
install:
|
||||
- "pip install -r requirements-dev.txt"
|
||||
- "pip install coveralls"
|
||||
- "pip install -e ."
|
||||
# command to run tests
|
||||
script:
|
||||
- python manage.py compile_translations
|
||||
- flaskbb translations compile
|
||||
- py.test --cov=flaskbb --cov-report=term-missing tests
|
||||
after_success:
|
||||
- coveralls
|
||||
@@ -1,4 +1,7 @@
|
||||
[ignore: .tox/**]
|
||||
[ignore: .venv/**]
|
||||
[ignore: **/plugins/**]
|
||||
[python: **.py]
|
||||
[ignore: **/node_modules/**]
|
||||
[python: **/flaskbb/**.py]
|
||||
[jinja2: **/templates/**.html]
|
||||
extensions=jinja2.ext.autoescape,jinja2.ext.with_
|
||||
+49
-19
@@ -22,14 +22,16 @@ from flask_migrate import upgrade as upgrade_database
|
||||
|
||||
from flaskbb import create_app
|
||||
from flaskbb._compat import iteritems
|
||||
from flaskbb.extensions import db, whooshee
|
||||
from flaskbb.extensions import db, whooshee, plugin_manager
|
||||
from flaskbb.utils.populate import (create_test_data, create_welcome_forum,
|
||||
create_user, create_default_groups,
|
||||
create_default_settings, insert_bulk_data,
|
||||
update_settings_from_fixture)
|
||||
from flaskbb.utils.translations import (add_translations, compile_translations,
|
||||
update_translations,
|
||||
add_plugin_translations)
|
||||
add_plugin_translations,
|
||||
compile_plugin_translations,
|
||||
update_plugin_translations)
|
||||
|
||||
_email_regex = r"[^@]+@[^@]+\.[^@]+"
|
||||
|
||||
@@ -56,17 +58,17 @@ class EmailType(click.ParamType):
|
||||
supported values. All of these values have to be strings.
|
||||
See :ref:`choice-opts` for an example.
|
||||
"""
|
||||
name = 'email'
|
||||
name = "email"
|
||||
|
||||
def convert(self, value, param, ctx):
|
||||
# Exact match
|
||||
if re.match(_email_regex, value):
|
||||
return value
|
||||
else:
|
||||
self.fail(('invalid email: %s' % value), param, ctx)
|
||||
self.fail(("invalid email: %s" % value), param, ctx)
|
||||
|
||||
def __repr__(self):
|
||||
return 'email'
|
||||
return "email"
|
||||
|
||||
|
||||
@click.group(cls=FlaskGroup, create_app=create_app)
|
||||
@@ -175,29 +177,57 @@ def translations():
|
||||
help="The plugin for which a language should be added.")
|
||||
@click.argument("lang")
|
||||
def new_translation(lang, plugin):
|
||||
"""Adds a new language to the translations. 'lang' is the language code
|
||||
of the language, like, 'de_AT'."""
|
||||
"""Adds a new language to the translations. "lang" is the language code
|
||||
of the language, like, "de_AT"."""
|
||||
if plugin:
|
||||
if plugin not in plugin_manager.all_plugins:
|
||||
raise FlaskBBCLIError("Plugin {} not found.".format(plugin),
|
||||
fg="red")
|
||||
click.secho("[+] Adding new language {} for plugin {}..."
|
||||
.format(lang, plugin), fg='cyan')
|
||||
.format(lang, plugin), fg="cyan")
|
||||
add_plugin_translations(plugin, lang)
|
||||
else:
|
||||
click.secho("[+] Adding new language {}...".format(lang), fg='cyan')
|
||||
click.secho("[+] Adding new language {}...".format(lang), fg="cyan")
|
||||
add_translations(lang)
|
||||
|
||||
|
||||
@translations.command("update")
|
||||
def update_translation():
|
||||
@click.option("is_all", "--all", "-a", default=True, is_flag=True,
|
||||
help="Updates the plugin translations as well.")
|
||||
@click.option("--plugin", "-p", type=click.STRING,
|
||||
help="The plugin for which the translations should be updated.")
|
||||
def update_translation(is_all, plugin):
|
||||
"""Updates all translations."""
|
||||
click.secho("[+] Updating language files...", fg='cyan')
|
||||
update_translations()
|
||||
if plugin is not None:
|
||||
if plugin not in plugin_manager.all_plugins:
|
||||
raise FlaskBBCLIError("Plugin {} not found.".format(plugin),
|
||||
fg="red")
|
||||
|
||||
click.secho("[+] Updating language files for plugin {}..."
|
||||
.format(plugin), fg="cyan")
|
||||
update_plugin_translations(plugin)
|
||||
else:
|
||||
click.secho("[+] Updating language files...", fg="cyan")
|
||||
update_translations(include_plugins=is_all)
|
||||
|
||||
|
||||
@translations.command("compile")
|
||||
def compile_translation(lang):
|
||||
@click.option("is_all", "--all", "-a", default=True, is_flag=True,
|
||||
help="Compiles the plugin translations as well.")
|
||||
@click.option("--plugin", "-p", type=click.STRING,
|
||||
help="The plugin for which the translations should be compiled.")
|
||||
def compile_translation(is_all, plugin):
|
||||
"""Compiles all translations."""
|
||||
click.secho("[+] Compiling language files...", fg='cyan')
|
||||
compile_translations()
|
||||
if plugin is not None:
|
||||
if plugin not in plugin_manager.all_plugins:
|
||||
raise FlaskBBCLIError("Plugin {} not found.".format(plugin),
|
||||
fg="red")
|
||||
click.secho("[+] Compiling language files for plugin {}..."
|
||||
.format(plugin), fg="cyan")
|
||||
compile_plugin_translations(plugin)
|
||||
else:
|
||||
click.secho("[+] Compiling language files...", fg="cyan")
|
||||
compile_translations(include_plugins=is_all)
|
||||
|
||||
|
||||
@cli.group()
|
||||
@@ -210,21 +240,21 @@ def plugins():
|
||||
@click.argument("plugin")
|
||||
def new_plugin(plugin):
|
||||
"""Creates a new plugin based on the plugin template."""
|
||||
click.secho("[+] Creating new Plugin {}...".format(plugin), fg='cyan')
|
||||
click.secho("[+] Creating new Plugin {}...".format(plugin), fg="cyan")
|
||||
|
||||
|
||||
@plugins.command("install")
|
||||
@click.argument("plugin")
|
||||
def install_plugin(plugin):
|
||||
"""Installs a new plugin from FlaskBB's Plugin Repository."""
|
||||
click.secho("[+] Installing plugin {}...".format(plugin), fg='cyan')
|
||||
"""Installs a new plugin from FlaskBB"s Plugin Repository."""
|
||||
click.secho("[+] Installing plugin {}...".format(plugin), fg="cyan")
|
||||
|
||||
|
||||
@plugins.command("uninstall")
|
||||
@click.argument("plugin")
|
||||
def uninstall_plugin(plugin):
|
||||
"""Uninstalls a plugin from FlaskBB."""
|
||||
click.secho("[+] Uninstalling plugin {}...".format(plugin), fg='cyan')
|
||||
click.secho("[+] Uninstalling plugin {}...".format(plugin), fg="cyan")
|
||||
|
||||
|
||||
@plugins.command("list")
|
||||
|
||||
@@ -78,8 +78,12 @@ class FlaskBBDomain(Domain):
|
||||
return translations
|
||||
|
||||
|
||||
def update_translations():
|
||||
"""Updates all translations."""
|
||||
def update_translations(include_plugins=False):
|
||||
"""Updates all translations.
|
||||
|
||||
:param include_plugins: If set to `True` it will also update the
|
||||
translations for all plugins.
|
||||
"""
|
||||
|
||||
# update flaskbb translations
|
||||
translations_folder = os.path.join(current_app.root_path, "translations")
|
||||
@@ -90,9 +94,10 @@ def update_translations():
|
||||
subprocess.call(["pybabel", "update", "-i", source_file,
|
||||
"-d", translations_folder])
|
||||
|
||||
# updates all plugin translations too
|
||||
for plugin in plugin_manager.all_plugins:
|
||||
update_plugin_translations(plugin)
|
||||
if include_plugins:
|
||||
# updates all plugin translations too
|
||||
for plugin in plugin_manager.all_plugins:
|
||||
update_plugin_translations(plugin)
|
||||
|
||||
|
||||
def add_translations(translation):
|
||||
@@ -107,16 +112,21 @@ def add_translations(translation):
|
||||
"-d", translations_folder, "-l", translation])
|
||||
|
||||
|
||||
def compile_translations():
|
||||
"""Compiles all translations."""
|
||||
def compile_translations(include_plugins=False):
|
||||
"""Compiles all translations.
|
||||
|
||||
:param include_plugins: If set to `True` it will also compile the
|
||||
translations for all plugins.
|
||||
"""
|
||||
|
||||
# compile flaskbb translations
|
||||
translations_folder = os.path.join(current_app.root_path, "translations")
|
||||
subprocess.call(["pybabel", "compile", "-d", translations_folder])
|
||||
|
||||
# compile all plugin translations
|
||||
for plugin in plugin_manager.all_plugins:
|
||||
compile_plugin_translations(plugin)
|
||||
if include_plugins:
|
||||
# compile all plugin translations
|
||||
for plugin in plugin_manager.all_plugins:
|
||||
compile_plugin_translations(plugin)
|
||||
|
||||
|
||||
def add_plugin_translations(plugin, translation):
|
||||
|
||||
Reference in new issue
Block a user