# HG changeset patch # User Andrey Skvortsov # Date 1484128660 -10800 # Node ID bc84d659894fac1aedbc6d41b8c3be63159059f0 # Parent aa9ec1d5c54c7b05688567925ee4bdd72895d502 move code in mki18n.py generated translation strings from custom files into separate function diff -r aa9ec1d5c54c -r bc84d659894f i18n/mki18n.py --- a/i18n/mki18n.py Wed Jan 11 11:40:53 2017 +0300 +++ b/i18n/mki18n.py Wed Jan 11 12:57:40 2017 +0300 @@ -108,7 +108,33 @@ return languageDict -XSD_STRING_MODEL = re.compile("]*\>") + + +def processCustomFiles(filein, fileout, regexp, prefix = ''): + appfil_file = open(filein, 'r') + messages_file = open(fileout, 'r') + messages = messages_file.read() + messages_file.close() + messages_file = open(fileout, 'a') + messages_file.write('\n') + messages_file.write('#: %s\n' % prefix) + messages_file.write('\n') + + words_found = {} + for filepath in appfil_file.xreadlines(): + code_file = open(filepath.strip(), 'r') + for match in regexp.finditer(code_file.read()): + word = match.group(1) + if not words_found.get(word, False) and messages.find("msgid \"%s\"\nmsgstr \"\"" % word) == -1: + words_found[word] = True + messages_file.write('\n') + messages_file.write("msgid \"%s\"\n"%word) + messages_file.write("msgstr \"\"\n") + code_file.close() + + messages_file.close() + appfil_file.close() + # ----------------------------------------------------------------------------- # m a k e P O ( ) -- Build the Portable Object file for the application -- @@ -143,10 +169,12 @@ else: applicationName = applicationDomain currentDir = os.getcwd() - os.chdir(applicationDirectoryPath) - if not os.path.exists('app.fil'): - raise IOError(2,'No module file: app.fil') - + os.chdir(applicationDirectoryPath) + filelist = 'app.fil' + if not os.path.exists(filelist): + raise IOError(2,'No module file: ' % filelist) + + fileout = 'messages.pot' # Steps: # Use xgettext to parse all application modules # The following switches are used: @@ -154,33 +182,16 @@ # -s : sort output by string content (easier to use when we need to merge several .po files) # --files-from=app.fil : The list of files is taken from the file: app.fil # --output= : specifies the name of the output file (using a .pot extension) - cmd = 'xgettext -s --no-wrap --language=Python --files-from=app.fil --output=messages.pot' + cmd = 'xgettext -s --no-wrap --language=Python --files-from=' + filelist + ' --output=' + fileout if verbose: print cmd os.system(cmd) - appfil_file = open("app.fil", 'r') - messages_file = open("messages.pot", 'r') - messages = messages_file.read() - messages_file.close() - messages_file = open("messages.pot", 'a') - messages_file.write(""" -#: Extra XSD strings -""") - words_found = {} - for filepath in appfil_file.xreadlines(): - code_file = open(filepath.strip(), 'r') - for match in XSD_STRING_MODEL.finditer(code_file.read()): - word = match.group(1) - if not words_found.get(word, False) and messages.find("msgid \"%s\"\nmsgstr \"\"" % word) == -1: - words_found[word] = True - messages_file.write(""" -msgid "%s" -msgstr "" -"""%word) - code_file.close() - messages_file.close() - appfil_file.close() - + XSD_STRING_MODEL = re.compile("]*\>") + processCustomFiles(filelist, fileout, XSD_STRING_MODEL, 'Extra XSD strings') + + XML_TC6_STRING_MODEL = re.compile("\s*\s*", re.MULTILINE | re.DOTALL) + processCustomFiles(filelist, fileout, XML_TC6_STRING_MODEL, 'Extra TC6 documentation strings') + languageDict = getlanguageDict() for langCode in languageDict.keys(): @@ -189,7 +200,7 @@ else: langPOfileName = "%s_%s.po" % (applicationName , langCode) if os.path.exists(langPOfileName): - cmd = 'msgmerge -s --no-wrap "%s" messages.pot > "%s.new"' % (langPOfileName, langPOfileName) + cmd = 'msgmerge -s --no-wrap "%s" %s > "%s.new"' % (langPOfileName, fileout, langPOfileName) if verbose: print cmd os.system(cmd) os.chdir(currentDir)