summaryrefslogtreecommitdiffstats
path: root/src/languages.py
blob: 5bb65cf5df047d71692e6793dd30a949f2cf58a7 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# This file is an aid to generate the Languages rules file.
# usage:
#   python languages.py > ..\winbuild\Languages.rules
#
import os
import re

files = [f for f in os.listdir('.') if re.match(r'translator_[a-z][a-z]\.h', f)]
new_list = []
for f in files:
    new_list.append([f,(os.path.splitext(f)[0]).replace("translator_","").upper()])

#
# generating file is lang_cfg.py
# the rules file has to output lang_cfg.h
#
print("""\
<?xml version="1.0" encoding="utf-8"?>
<VisualStudioToolFile
        Name="languages"
        Version="8.00"
        >
        <Rules>
                <CustomBuildRule
                        Name="Languages"
                        DisplayName="Settings"
                        CommandLine="python $(InputPath) [AllOptions] [AdditionalOptions] &gt; $(InpDir)/$(InputName).h"
                        Outputs="$(IntDir)/$(InputName).h"
                        FileExtensions="*.py"
                        AdditionalDependencies=""
                        ExecutionDescription="Executing languages ..."
                        ShowOnlyRuleProperties="false"
                        >
                        <Properties>
                               <EnumProperty
                                       Name="EnglishOnly"
                                       DisplayName="Use English Only"
                                       Description="Use English Only"
                                       DefaultValue="0"
                               >
                                       <Values>
                                               <EnumValue
                                               Value="0"
                                               Switch=""
                                               DisplayName="Don't use English Only"
                                               />
                                               <EnumValue
                                               Value="1"
                                               Switch="ENONLY"
                                               DisplayName="Use English Only"
                                               />
                                       </Values>
                               </EnumProperty>
""")
#
# generate loop, English is mandatory (so cannot be chosen)
#
for f in new_list:
    if (f[1] != "EN"):
        # search for the language description
        fil = open(f[0], 'r')
        tmp = ""
        for line in fil:
          if "idLanguage" in line:
             tmp = line
             if "}" in line:
               break
          elif (tmp != ""):
             tmp += line
             if "}" in line:
               break
    
        tmp = tmp.replace("\n","")
        l = re.sub('[^"]*"([^"]*)".*','\\1',tmp)
        l1 = l.replace("-","")
        # capatalize first letter
        l = l.title()
        print("""\
                                   <EnumProperty
                                           Name="%s"
                                           DisplayName="Use %s"
                                           Description="Use %s"
                                           DefaultValue="1"
                                   >
                                           <Values>
                                                   <EnumValue
                                                   Value="0"
                                                   Switch=""
                                                   DisplayName="Don't use %s"
                                                   />
                                                   <EnumValue
                                                   Value="1"
                                                   Switch="%s"
                                                   DisplayName="Use %s"
                                                   />
                                           </Values>
                                   </EnumProperty>
        """ % (l1, l, l, l, f[1], l))

print("""\
                        </Properties>
                </CustomBuildRule>
        </Rules>
</VisualStudioToolFile>
""")