14 python translator.py en nl cz |
14 python translator.py en nl cz |
15 |
15 |
16 Originally, the script was written in Perl and was known as translator.pl. |
16 Originally, the script was written in Perl and was known as translator.pl. |
17 The last Perl version was dated 2002/05/21 (plus some later corrections) |
17 The last Perl version was dated 2002/05/21 (plus some later corrections) |
18 |
18 |
19 $Id: translator.py 708 2009-10-04 20:20:24Z dimitri $ |
19 $Id: translator.py 721 2010-02-16 21:11:17Z dimitri $ |
20 |
20 |
21 Petr Prikryl (prikrylp@skil.cz) |
21 Petr Prikryl (prikrylp@skil.cz) |
22 |
22 |
23 History: |
23 History: |
24 -------- |
24 -------- |
171 self.txtMAX_DOT_GRAPH_HEIGHT_flag = False # found in string in trLegendDocs() |
171 self.txtMAX_DOT_GRAPH_HEIGHT_flag = False # found in string in trLegendDocs() |
172 self.obsoleteMethods = None # list of prototypes to be removed |
172 self.obsoleteMethods = None # list of prototypes to be removed |
173 self.missingMethods = None # list of prototypes to be implemented |
173 self.missingMethods = None # list of prototypes to be implemented |
174 self.implementedMethods = None # list of implemented required methods |
174 self.implementedMethods = None # list of implemented required methods |
175 self.adaptMinClass = None # The newest adapter class that can be used |
175 self.adaptMinClass = None # The newest adapter class that can be used |
176 |
176 self.isDecodedTranslator = None # Flag related to internal usage of UTF-8 |
177 |
177 |
178 def __tokenGenerator(self): |
178 def __tokenGenerator(self): |
179 """Generator that reads the file and yields tokens as 4-tuples. |
179 """Generator that reads the file and yields tokens as 4-tuples. |
180 |
180 |
181 The tokens have the form (tokenId, tokenString, lineNo). The |
181 The tokens have the form (tokenId, tokenString, lineNo). The |
1092 if myDic.has_key(p): |
1092 if myDic.has_key(p): |
1093 self.implementedMethods.append(p) |
1093 self.implementedMethods.append(p) |
1094 else: |
1094 else: |
1095 self.missingMethods.append(p) |
1095 self.missingMethods.append(p) |
1096 |
1096 |
|
1097 # Set the least important note first if the translator is decoded. |
|
1098 # If yes, then it means that the implementation should be switched |
|
1099 # to UTF-8 later (suggestion). |
|
1100 self.isDecodedTranslator = self.classId in self.manager.decodedTranslators |
|
1101 if self.isDecodedTranslator: |
|
1102 self.note = 'Reimplementation using UTF-8 suggested.' |
|
1103 |
1097 # Check whether adapter must be used or suggest the newest one. |
1104 # Check whether adapter must be used or suggest the newest one. |
1098 # Change the status and set the note accordingly. |
1105 # Change the status and set the note accordingly. |
1099 if self.baseClassId != 'Translator': |
1106 if self.baseClassId != 'Translator': |
1100 if not self.missingMethods: |
1107 if not self.missingMethods: |
1101 self.note = 'Change the base class to Translator.' |
1108 self.note = 'Change the base class to Translator.' |
1275 self.langLst = None # including English based |
1282 self.langLst = None # including English based |
1276 self.supportedLangReadableStr = None # coupled En-based as a note |
1283 self.supportedLangReadableStr = None # coupled En-based as a note |
1277 self.numLang = None # excluding coupled En-based |
1284 self.numLang = None # excluding coupled En-based |
1278 self.doxVersion = None # Doxygen version |
1285 self.doxVersion = None # Doxygen version |
1279 |
1286 |
|
1287 # Capture the knowledge about translators that are not implemented |
|
1288 # to use UTF-8 internally. |
|
1289 self.decodedTranslators = self.getDecodedTranslators() |
|
1290 |
1280 # Build objects where each one is responsible for one translator. |
1291 # Build objects where each one is responsible for one translator. |
1281 self.__build() |
1292 self.__build() |
1282 |
1293 |
|
1294 |
|
1295 def getDecodedTranslators(self): |
|
1296 """Parses language.cpp to find what translators do not use UTF-8 yet""" |
|
1297 decodedTranslators = [] |
|
1298 |
|
1299 # Regular expression to detect the lines like |
|
1300 # theTranslator=new TranslatorDecoder(new TranslatorSwedish); |
|
1301 rex = re.compile(r'^\s*theTranslator\s*=\s*new\s+.*$') |
|
1302 |
|
1303 # Regular expression to get the (optional) TranslatorDecoder and TranslatorXXX |
|
1304 rex2 = re.compile(r'\bTranslator\w+') |
|
1305 |
|
1306 # Parse the lines in the specific source code. |
|
1307 f = open(os.path.join(self.src_path, 'language.cpp'), 'rU') |
|
1308 for line in f: |
|
1309 if rex.match(line): |
|
1310 lst = rex2.findall(line) |
|
1311 if lst[0] == 'TranslatorDecoder': |
|
1312 decodedTranslators.append(lst[1]) |
|
1313 f.close() |
|
1314 |
|
1315 # Display warning when all translator implementations were converted |
|
1316 # to UTF-8. |
|
1317 if len(decodedTranslators) == 0: |
|
1318 print 'This script should be updated. All translators do use UTF-8' |
|
1319 print 'internally. The TranslatorDecoder adapter should be removed' |
|
1320 print 'from the code and its usage should not be checked any more.' |
|
1321 |
|
1322 return decodedTranslators |
|
1323 |
1283 |
1324 |
1284 def __build(self): |
1325 def __build(self): |
1285 """Find the translator files and build the objects for translators.""" |
1326 """Find the translator files and build the objects for translators.""" |
1286 |
1327 |
1287 # The translator.h must exist (the Transl object will check it), |
1328 # The translator.h must exist (the Transl object will check it), |