2020-11-15 23:29:26 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2021-04-22 14:20:24 +00:00
|
|
|
|
2020-11-15 23:29:26 +00:00
|
|
|
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
|
|
|
|
"""
|
2021-05-12 15:43:18 +00:00
|
|
|
|
2020-11-15 23:29:26 +00:00
|
|
|
def handle(self, *args, **kwargs):
|
|
|
|
for code, _ in settings.LANGUAGES:
|
|
|
|
if code == settings.LANGUAGE_CODE:
|
|
|
|
continue
|
2021-04-14 13:18:24 +00:00
|
|
|
if kwargs["verbosity"] > 0:
|
|
|
|
self.stdout.write(f"Generate {code} javascript localization file")
|
2020-11-15 23:29:26 +00:00
|
|
|
with translation.override(code):
|
|
|
|
resp = JavaScriptCatalog().get(None, packages="member+note")
|
2021-04-22 14:20:24 +00:00
|
|
|
if not os.path.isdir(settings.STATIC_ROOT + "/js/jsi18n"):
|
|
|
|
os.makedirs(settings.STATIC_ROOT + "/js/jsi18n")
|
|
|
|
with open(settings.STATIC_ROOT + f"/js/jsi18n/{code}.js", "wb") as f:
|
2020-11-15 23:29:26 +00:00
|
|
|
f.write(resp.content)
|