[damned-lies] Add --locale option to compile-trans command
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Add --locale option to compile-trans command
- Date: Sun, 21 Mar 2021 18:15:16 +0000 (UTC)
commit 6b903da535e94bebcf6b044c27df60f2f364b5e0
Author: Claude Paroz <claude 2xlibre net>
Date: Sun Mar 21 17:52:37 2021 +0100
Add --locale option to compile-trans command
stats/management/commands/compile-trans.py | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/stats/management/commands/compile-trans.py b/stats/management/commands/compile-trans.py
index 3387e2e6..7954aec1 100644
--- a/stats/management/commands/compile-trans.py
+++ b/stats/management/commands/compile-trans.py
@@ -10,6 +10,14 @@ from languages.models import Language
class Command(BaseCommand):
help = "Compile translations of djamnedlies"
+ def add_arguments(self, parser):
+ # Copy --locale arg from compilemessages
+ parser.add_argument(
+ '--locale', '-l', action='append', default=[],
+ help='Locale(s) to process (e.g. de_AT). Default is to process all. '
+ 'Can be used multiple times.',
+ )
+
def handle(self, **options):
# Copy all po/ll.po files in locale/ll/LC_MESSAGES/django.po
podir = settings.BASE_DIR / 'po'
@@ -17,12 +25,19 @@ class Command(BaseCommand):
if pofile.suffix != ".po":
continue
lang_code = pofile.stem
+ if options['locale'] and lang_code not in options['locale']:
+ continue
localedir = (
settings.BASE_DIR / 'locale' / Language.django_locale(lang_code) / 'LC_MESSAGES'
)
if not localedir.is_dir():
localedir.mkdir(parents=True, exist_ok=True)
+ if options['verbosity'] > 1:
+ self.stdout.write(f"Copying {pofile} to {localedir}")
shutil.copy(pofile, localedir / 'django.po')
# Run compilemessages -l ll
- call_command('compilemessages')
+ call_command(
+ 'compilemessages',
+ locale=[Language.django_locale(locale) for locale in options['locale']]
+ )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]