Spaces:
Sleeping
Sleeping
Update server/babel.py
Browse files- server/babel.py +19 -12
server/babel.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import subprocess
|
3 |
from flask import request, session, jsonify
|
4 |
from flask_babel import Babel
|
@@ -34,15 +35,21 @@ def get_languages():
|
|
34 |
return jsonify(BABEL_LANGUAGES)
|
35 |
|
36 |
|
37 |
-
def compile_translations():
|
38 |
-
"""Compile the translation files."""
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import stat
|
3 |
import subprocess
|
4 |
from flask import request, session, jsonify
|
5 |
from flask_babel import Babel
|
|
|
35 |
return jsonify(BABEL_LANGUAGES)
|
36 |
|
37 |
|
38 |
+
def compile_translations():
|
39 |
+
"""Compile the translation files."""
|
40 |
+
|
41 |
+
for root, dirs, files in os.walk('translations'):
|
42 |
+
os.chmod(root, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
43 |
+
for d in dirs:
|
44 |
+
os.chmod(os.path.join(root, d), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
45 |
+
|
46 |
+
result = subprocess.run(
|
47 |
+
['pybabel', 'compile', '-d', 'translations'],
|
48 |
+
stdout=subprocess.PIPE,
|
49 |
+
)
|
50 |
+
|
51 |
+
if result.returncode != 0:
|
52 |
+
raise Exception(
|
53 |
+
f'Compiling translations failed:\n{result.stdout.decode()}')
|
54 |
+
|
55 |
+
print('Translations compiled successfully')
|