mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-25 00:42:23 +00:00
Export JS translation files as static files
This commit is contained in:
parent
654492f9e9
commit
dbe7bf6591
28
management/commands/compilejsmessages.py
Normal file
28
management/commands/compilejsmessages.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils import translation
|
||||
from django.views.i18n import JavaScriptCatalog
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Generate Javascript translation files
|
||||
"""
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--out', '-o', type=str, default='static', help='Output directory, where static files are.')
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
for code, _ in settings.LANGUAGES:
|
||||
if code == settings.LANGUAGE_CODE:
|
||||
continue
|
||||
self.stdout.write(f"Generate {code} javascript localization file")
|
||||
with translation.override(code):
|
||||
resp = JavaScriptCatalog().get(None, packages="member+note")
|
||||
if not os.path.isdir(kwargs["out"] + "/js/jsi18n"):
|
||||
os.makedirs(kwargs["out"] + "/js/jsi18n")
|
||||
with open(kwargs["out"] + f"/js/jsi18n/{code}.js", "wb") as f:
|
||||
f.write(resp.content)
|
Loading…
Reference in New Issue
Block a user