zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
from django.core.management.base import BaseCommand
from django.core.management import call_command
 
from app.scripts.extract_odm_strings import extract_odm_strings
from app.scripts.extract_plugin_manifest_strings import extract_plugin_manifest_strings
from app.scripts.extract_potree_strings import extract_potree_strings
 
root = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", ".."))
 
class Command(BaseCommand):
    requires_system_checks = []
 
    def add_arguments(self, parser):
        parser.add_argument("action", type=str, choices=['extract', 'build'])
        parser.add_argument("--safe", action='store_true', required=False, help="Skip invalid languages")
        super(Command, self).add_arguments(parser)
 
    def handle(self, **options):
        with open(os.path.join(root, "LOCALES")) as f:
            locales = f.read().strip().split(" ")
        
        if options.get('action') == 'extract':
            print("Extracting .po files from Django/React")
            locale_params = ["--locale=%s" % l for l in locales]
            
            locale_dir = os.path.join(root, "locale")
            if not os.path.exists(locale_dir):
                os.mkdir(locale_dir)
            
            extract_potree_strings(
                os.path.join(root, "app", "static", "app", "js", "vendor", "potree", "build", "potree", "resources", "lang", "en", "translation.json"), 
                os.path.join(root, "app", "static", "app", "js", "translations", "potree_autogenerated.js")
            )
            extract_odm_strings(
                "https://raw.githubusercontent.com/OpenDroneMap/ODM/master/opendm/config.py",
                os.path.join(root, "app", "static", "app", "js", "translations", "odm_autogenerated.js")
            )
            extract_plugin_manifest_strings(
                os.path.join(root, "coreplugins"), 
                os.path.join(root, "app", "translations", "plugin_manifest_autogenerated.py")
            )
 
            call_command('makemessages', '--keep-pot', *locale_params, '--ignore=build', '--ignore=app/templates/app/registration/*')
            call_command('makemessages_djangojs', '--keep-pot', *locale_params, '-d=djangojs', '--extension=jsx', '--extension=js', '--ignore=build', '--ignore=app/static/app/js/vendor', '--ignore=app/static/app/bundles', '--ignore=node_modules', '--language=Python')
 
        elif options.get('action') == 'build':
            if options.get('safe'):
                for l in locales:
                    print("Building %s .po files into .mo" % l)
                    call_command('compilemessages', '--locale=%s' % l)
            else:
                print("Building .po files into .mo")
                call_command('compilemessages')