2
2
import re
3
3
import shutil
4
4
import tempfile
5
- import urllib
6
5
7
6
from base .management import BaseCommand
8
- from django .core .management import call_command
9
7
from django .core .management .commands import makemessages
10
- from django .core .management .utils import popen_wrapper
11
- from django .utils .translation import templatize
12
8
from django .utils .functional import cached_property
13
- from django .utils .jslex import JsLexer , Tok
14
- JsLexer .both_before .append (Tok ("template" , r"`([^\\]|(\\(.|\n)))*?`" , next = "div" ),)
9
+ from django .utils .jslex import JsLexer
10
+ from django .utils .jslex import Tok
11
+ from django .utils .translation import templatize
12
+
13
+ JsLexer .both_before .append (
14
+ Tok ("template" , r"`([^\\]|(\\(.|\n)))*?`" , next = "div" ),
15
+ )
15
16
16
17
# This makes makemessages create both translations for Python and JavaScript
17
18
# code in one go.
@@ -54,12 +55,12 @@ def escape_quotes(m):
54
55
tok = '"' + guts + '"'
55
56
elif name == "template" :
56
57
# Split the template string into chunks using the ${...} pattern
57
- chunks = re .findall (r' \${(.*?)}' , tok )
58
+ chunks = re .findall (r" \${(.*?)}" , tok )
58
59
# Concatenate the chunks with "+"
59
60
for chunk in chunks :
60
- tok = tok .replace ('${' + chunk + '}' , '" + ' + chunk + ' + "' , 1 )
61
+ tok = tok .replace ("${" + chunk + "}" , '" + ' + chunk + ' + "' , 1 )
61
62
# Replace backtick-quotes with double-quotes.
62
- tok = '"' + tok [1 :- 1 ] + '"'
63
+ tok = '"' + tok [1 :- 1 ] + '"'
63
64
elif name == "id" :
64
65
# C can't deal with Unicode escapes in identifiers. We don't
65
66
# need them for gettext anyway, so replace them with something
@@ -70,7 +71,6 @@ def escape_quotes(m):
70
71
71
72
72
73
class BuildFile (makemessages .BuildFile ):
73
-
74
74
@cached_property
75
75
def is_templatized (self ):
76
76
if self .domain == "djangojs" :
@@ -101,11 +101,11 @@ def preprocess(self):
101
101
def cleanup (self ):
102
102
pass
103
103
104
+
104
105
class Command (makemessages .Command , BaseCommand ):
105
106
build_file_class = BuildFile
106
107
107
108
def handle (self , * args , ** options ):
108
- #call_command("transpile")
109
109
options ["ignore_patterns" ] += [
110
110
"venv" ,
111
111
".direnv" ,
@@ -120,41 +120,3 @@ def handle(self, *args, **options):
120
120
super ().handle (* args , ** options )
121
121
shutil .rmtree (self .temp_dir_in )
122
122
shutil .rmtree (self .temp_dir_out )
123
-
124
- # def process_locale_dir(self, locale_dir, files):
125
- # if self.domain == "djangojs":
126
- # for file in files:
127
- # # We need to copy the JS files first, as otherwise babel will
128
- # # attempt to read package.json files in subdirs, such as
129
- # # base/package.json
130
- # in_path = urllib.parse.urljoin(self.temp_dir_in + "/", file.dirpath)
131
- # os.makedirs(in_path, exist_ok=True)
132
- # in_file = urllib.parse.urljoin(in_path + "/", file.file)
133
- # shutil.copy2(file.path, in_file)
134
- # out_path = urllib.parse.urljoin(self.temp_dir_out + "/", file.dirpath)
135
- # file.dirpath = out_path
136
- # os.chdir(".transpile/")
137
- # out, err, status = popen_wrapper(
138
- # [
139
- # "npm",
140
- # "run",
141
- # "babel-transform-template-literals",
142
- # "--",
143
- # "--out-dir",
144
- # self.temp_dir_out,
145
- # self.temp_dir_in,
146
- # ],
147
- # )
148
- # os.chdir("../")
149
- #
150
- # super().process_locale_dir(locale_dir, files)
151
- #
152
- # def write_po_file(self, potfile, locale):
153
- # if self.domain == "djangojs":
154
- # with open(potfile, encoding="utf-8") as fp:
155
- # msgs = fp.read()
156
- # # Remove temp dir path info
157
- # msgs = msgs.replace(self.temp_dir_out + "/", "")
158
- # with open(potfile, "w", encoding="utf-8") as fp:
159
- # fp.write(msgs)
160
- # super().write_po_file(potfile, locale)
0 commit comments