1
1
#!/usr/bin/env python3
2
+ # Dependencies:
3
+ # $ sudo apt-get install python3-requests gettext qt6-l10n-tools
4
+
2
5
import os
3
6
import subprocess
4
7
import sys
8
11
except ImportError as e :
9
12
sys .exit (f"Error: { str (e )} . Try 'python3 -m pip install --user <module-name>'" )
10
13
11
-
14
+ # set cwd
12
15
project_root = os .path .abspath (os .path .dirname (os .path .dirname (__file__ )))
13
-
14
16
os .chdir (project_root )
15
17
18
+ # check dependencies are available
19
+ try :
20
+ subprocess .check_output (["xgettext" , "--version" ])
21
+ subprocess .check_output (["msgcat" , "--version" ])
22
+ except (subprocess .CalledProcessError , OSError ) as e2 :
23
+ raise Exception ("missing gettext. Maybe try 'apt install gettext'" )
24
+
25
+ QT_LUPDATE = "lupdate"
26
+ QT_LCONVERT = "lconvert"
27
+ try :
28
+ subprocess .check_output ([QT_LUPDATE , "-version" ])
29
+ subprocess .check_output ([QT_LCONVERT , "-h" ])
30
+ except (subprocess .CalledProcessError , OSError ) as e1 :
31
+ QT_LUPDATE = "/usr/lib/qt6/bin/lupdate" # workaround qt5/qt6 confusion on ubuntu 22.04
32
+ QT_LCONVERT = "/usr/lib/qt6/bin/lconvert"
33
+ try :
34
+ subprocess .check_output ([QT_LUPDATE , "-version" ])
35
+ subprocess .check_output ([QT_LCONVERT , "-h" ])
36
+ except (subprocess .CalledProcessError , OSError ) as e2 :
37
+ raise Exception ("missing Qt lupdate/convert tools. Maybe try 'apt install qt6-l10n-tools'" )
38
+
39
+
16
40
cmd = "find electrum -type f -name '*.py' -o -name '*.kv'"
17
41
files = subprocess .check_output (cmd , shell = True )
18
42
@@ -38,13 +62,13 @@ with open("electrum/locale/qml.lst", "wb") as f:
38
62
39
63
print ("Found {} QML files to translate" .format (len (files .splitlines ())))
40
64
41
- cmd = "lupdate @electrum/locale/qml.lst -ts electrum/locale/qml.ts"
65
+ cmd = [ QT_LUPDATE , " @electrum/locale/qml.lst" , " -ts" , " electrum/locale/qml.ts"]
42
66
print ('Collecting strings' )
43
- subprocess .check_output (cmd , shell = True )
67
+ subprocess .check_output (cmd )
44
68
45
- cmd = "lconvert -of po -o electrum/locale/messages_qml.pot electrum/locale/qml.ts"
69
+ cmd = [ QT_LCONVERT , " -of" , "po" , "-o" , " electrum/locale/messages_qml.pot" , " electrum/locale/qml.ts"]
46
70
print ('Convert to gettext' )
47
- subprocess .check_output (cmd , shell = True )
71
+ subprocess .check_output (cmd )
48
72
49
73
cmd = "msgcat -u -o electrum/locale/messages.pot electrum/locale/messages_gettext.pot electrum/locale/messages_qml.pot"
50
74
print ('Generate template' )
0 commit comments