|
1 |
| -############################################################################## |
2 |
| -# |
3 |
| -# PROJECT: Multi Theft Auto v1.0 |
4 |
| -# LICENSE: See LICENSE in the top level directory |
5 |
| -# FILE: utils/build_gettext_catalog.py |
6 |
| -# PURPOSE: Create a template .pot file from .cpp and .h project files for client and server |
7 |
| -# DEVELOPERS: Dan Chowdhury <> |
8 |
| -# |
9 |
| -# Multi Theft Auto is available from http://www.multitheftauto.com/ |
10 |
| -# |
11 |
| -############################################################################## |
12 |
| - |
13 |
| -import os |
14 |
| -import subprocess |
15 |
| -import tempfile |
16 |
| -from optparse import OptionParser |
17 |
| - |
18 |
| -parser = OptionParser() |
19 |
| -parser.add_option("-e", "--exe", dest="exe", |
20 |
| - help="xgettext executable location", default="C:/Program Files (x86)/Poedit/GettextTools/bin/xgettext.exe" ) |
21 |
| -#parser.add_option("-f", "--file", dest="output", |
22 |
| -# help="POT File output directory", default="messages") |
23 |
| -parser.add_option("-v", "--version", dest="version", |
24 |
| - help="MTA:SA Version to write to the POT file", default="1.x") |
25 |
| - |
26 |
| -(options, args) = parser.parse_args() |
27 |
| - |
28 |
| -directories = { |
29 |
| - "client.pot" : [ "../MTA10", "../Shared" ], |
30 |
| - #"../MTA10/locale/client.pot" : [ "../MTA10_Server", "../Shared" ], |
31 |
| -} |
32 |
| - |
33 |
| -scanDirsList = [] |
34 |
| - |
35 |
| -fd,temp_path = tempfile.mkstemp() |
36 |
| - |
37 |
| -# The objective here is to scan for all our .cpp's and .h's in each root directory |
38 |
| -# We then compile a list of these files into a temporary file, which is given to xgettext |
39 |
| -# xgettext then reads this list, and produces our template .po file which is renamed to .pot |
40 |
| -for output,dirList in directories.iteritems(): |
41 |
| - scanDirsFile = open(temp_path, 'w') |
42 |
| - # Scan for .cpp and .h files |
43 |
| - for dir in dirList: |
44 |
| - for root,dirs,files in os.walk(dir): |
45 |
| - for file in files: |
46 |
| - filename,ext = os.path.splitext(file) |
47 |
| - if ext == ".c" or ext == ".cpp" or ext == ".h" or ext == ".hpp": |
48 |
| - filePath = os.path.abspath(os.path.join(root,file)) |
49 |
| - print ( filePath ) |
50 |
| - # Add each file to a list |
51 |
| - scanDirsList.append ( filePath + "\n" ) |
52 |
| - |
53 |
| - print ( "Files found: " + str(len(scanDirsList)) ) |
54 |
| - |
55 |
| - # Write this to our temporary file |
56 |
| - scanDirsFile.writelines(scanDirsList) |
57 |
| - scanDirsFile.close() |
58 |
| - |
59 |
| - # If we have .pot in the destination, strip it (xgettext seems to append an extension regardless) |
60 |
| - path,ext = os.path.splitext(output) |
61 |
| - if ext == ".pot": |
62 |
| - output = path |
63 |
| - |
64 |
| - # Give xgettext our temporary file to produce our .po |
65 |
| - cmdArgs = [options.exe,"-f",os.path.abspath(scanDirsFile.name),"-d",output, |
66 |
| - "--c++","--from-code=UTF-8","--add-comments", |
67 |
| - "--keyword=_", "--keyword=_td", "--keyword=_tn:1,2", "--keyword=_tc:1c,2", "--keyword=_tcn:1c,2,3", |
68 |
| - "--package-name=MTA San Andreas","--package-version="+options.version] |
69 |
| - |
70 |
| - proc = subprocess.Popen(cmdArgs) |
71 |
| - stdout, stderr = proc.communicate() |
72 |
| - print stdout |
73 |
| - print stderr |
74 |
| - |
75 |
| - #Rename our template to .pot (xgettext always outputs .po) |
76 |
| - if os.path.isfile(output + ".pot"): |
77 |
| - os.remove(output + ".pot") |
78 |
| - if os.path.isfile(output + ".po"): |
79 |
| - os.rename(output + ".po", output + ".pot") |
80 |
| - |
81 |
| -# Delete our temporary file |
82 |
| -os.close(fd) |
83 |
| -os.remove(temp_path) |
84 |
| - |
85 |
| - |
86 |
| -print ( "POT Generation Operation Complete" ) |
| 1 | +############################################################################## |
| 2 | +# |
| 3 | +# PROJECT: Multi Theft Auto v1.0 |
| 4 | +# LICENSE: See LICENSE in the top level directory |
| 5 | +# FILE: utils/build_gettext_catalog.py |
| 6 | +# PURPOSE: Create a template .pot file from .cpp and .h project files for client and server |
| 7 | +# DEVELOPERS: Dan Chowdhury <> |
| 8 | +# |
| 9 | +# Multi Theft Auto is available from http://www.multitheftauto.com/ |
| 10 | +# |
| 11 | +############################################################################## |
| 12 | + |
| 13 | +import os |
| 14 | +import subprocess |
| 15 | +import tempfile |
| 16 | +from optparse import OptionParser |
| 17 | + |
| 18 | +parser = OptionParser() |
| 19 | +parser.add_option("-e", "--exe", dest="exe", |
| 20 | + help="xgettext executable location", default="C:/Program Files (x86)/Poedit/GettextTools/bin/xgettext.exe" ) |
| 21 | +#parser.add_option("-f", "--file", dest="output", |
| 22 | +# help="POT File output directory", default="messages") |
| 23 | +parser.add_option("-v", "--version", dest="version", |
| 24 | + help="MTA:SA Version to write to the POT file", default="1.x") |
| 25 | + |
| 26 | +(options, args) = parser.parse_args() |
| 27 | + |
| 28 | +directories = { |
| 29 | + "client.pot" : [ "../MTA10", "../Shared" ], |
| 30 | + #"../MTA10/locale/client.pot" : [ "../MTA10_Server", "../Shared" ], |
| 31 | +} |
| 32 | + |
| 33 | +scanDirsList = [] |
| 34 | + |
| 35 | +fd,temp_path = tempfile.mkstemp() |
| 36 | + |
| 37 | +# The objective here is to scan for all our .cpp's and .h's in each root directory |
| 38 | +# We then compile a list of these files into a temporary file, which is given to xgettext |
| 39 | +# xgettext then reads this list, and produces our template .po file which is renamed to .pot |
| 40 | +for output,dirList in directories.iteritems(): |
| 41 | + scanDirsFile = open(temp_path, 'w') |
| 42 | + # Scan for .cpp and .h files |
| 43 | + for dir in dirList: |
| 44 | + for root,dirs,files in os.walk(dir): |
| 45 | + for file in files: |
| 46 | + filename,ext = os.path.splitext(file) |
| 47 | + if ext == ".c" or ext == ".cpp" or ext == ".h" or ext == ".hpp": |
| 48 | + filePath = os.path.abspath(os.path.join(root,file)) |
| 49 | + print ( filePath ) |
| 50 | + # Add each file to a list |
| 51 | + scanDirsList.append ( filePath + "\n" ) |
| 52 | + |
| 53 | + print ( "Files found: " + str(len(scanDirsList)) ) |
| 54 | + |
| 55 | + # Write this to our temporary file |
| 56 | + scanDirsFile.writelines(scanDirsList) |
| 57 | + scanDirsFile.close() |
| 58 | + |
| 59 | + # If we have .pot in the destination, strip it (xgettext seems to append an extension regardless) |
| 60 | + path,ext = os.path.splitext(output) |
| 61 | + if ext == ".pot": |
| 62 | + output = path |
| 63 | + |
| 64 | + # Give xgettext our temporary file to produce our .po |
| 65 | + cmdArgs = [options.exe,"-f",os.path.abspath(scanDirsFile.name),"-d",output, |
| 66 | + "--c++","--from-code=UTF-8","--add-comments", |
| 67 | + "--keyword=_", "--keyword=_td", "--keyword=_tn:1,2", "--keyword=_tc:1c,2", "--keyword=_tcn:1c,2,3", |
| 68 | + "--package-name=MTA San Andreas","--package-version="+options.version] |
| 69 | + |
| 70 | + proc = subprocess.Popen(cmdArgs) |
| 71 | + stdout, stderr = proc.communicate() |
| 72 | + print stdout |
| 73 | + print stderr |
| 74 | + |
| 75 | + #Rename our template to .pot (xgettext always outputs .po) |
| 76 | + if os.path.isfile(output + ".pot"): |
| 77 | + os.remove(output + ".pot") |
| 78 | + if os.path.isfile(output + ".po"): |
| 79 | + os.rename(output + ".po", output + ".pot") |
| 80 | + |
| 81 | +# Delete our temporary file |
| 82 | +os.close(fd) |
| 83 | +os.remove(temp_path) |
| 84 | + |
| 85 | + |
| 86 | +print ( "POT Generation Operation Complete" ) |
0 commit comments