i18n/mki18n.py
changeset 2459 21164625b393
parent 2452 2f2b2152580f
child 3750 f62625418bff
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
    82 from __future__ import absolute_import
    82 from __future__ import absolute_import
    83 from __future__ import print_function
    83 from __future__ import print_function
    84 import os
    84 import os
    85 import sys
    85 import sys
    86 import re
    86 import re
       
    87 from builtins import str as text
    87 import wx
    88 import wx
       
    89 
    88 
    90 
    89 # -----------------------------------------------------------------------------
    91 # -----------------------------------------------------------------------------
    90 # Global variables
    92 # Global variables
    91 # ----------------
    93 # ----------------
    92 #
    94 #
   147     messages_file.write('\n')
   149     messages_file.write('\n')
   148     messages_file.write('#: %s\n' % prefix)
   150     messages_file.write('#: %s\n' % prefix)
   149     messages_file.write('\n')
   151     messages_file.write('\n')
   150 
   152 
   151     words_found = {}
   153     words_found = {}
   152     for filepath in appfil_file.xreadlines():
   154     for filepath in appfil_file.readlines():
   153         code_file = open(filepath.strip(), 'r')
   155         code_file = open(filepath.strip(), 'r')
   154         for match in regexp.finditer(code_file.read()):
   156         for match in regexp.finditer(code_file.read()):
   155             word = match.group(1)
   157             word = match.group(1)
   156             if not words_found.get(word, False) and messages.find("msgid \"%s\"\nmsgstr \"\"" % word) == -1:
   158             if not words_found.get(word, False) and messages.find("msgid \"%s\"\nmsgstr \"\"" % word) == -1:
   157                 words_found[word] = True
   159                 words_found[word] = True
   198         applicationName = applicationDomain
   200         applicationName = applicationDomain
   199     currentDir = os.getcwd()
   201     currentDir = os.getcwd()
   200     os.chdir(applicationDirectoryPath)
   202     os.chdir(applicationDirectoryPath)
   201     filelist = 'app.fil'
   203     filelist = 'app.fil'
   202     if not os.path.exists(filelist):
   204     if not os.path.exists(filelist):
   203         raise IOError(2, 'No module file: ' % filelist)
   205         raise IOError(2, 'No module file: %s' % filelist)
   204 
   206 
   205     fileout = 'messages.pot'
   207     fileout = 'messages.pot'
   206     # Steps:
   208     # Steps:
   207     #  Use xgettext to parse all application modules
   209     #  Use xgettext to parse all application modules
   208     #  The following switches are used:
   210     #  The following switches are used:
   212     #   --output=                   : specifies the name of the output file (using a .pot extension)
   214     #   --output=                   : specifies the name of the output file (using a .pot extension)
   213     cmd = 'xgettext -s --no-wrap --language=Python --files-from=' + filelist + ' --output=' + fileout + ' --package-name ' + applicationName
   215     cmd = 'xgettext -s --no-wrap --language=Python --files-from=' + filelist + ' --output=' + fileout + ' --package-name ' + applicationName
   214     verbosePrint(verbose, cmd)
   216     verbosePrint(verbose, cmd)
   215     os.system(cmd)
   217     os.system(cmd)
   216 
   218 
   217     XSD_STRING_MODEL = re.compile("<xsd\:(?:element|attribute) name=\"([^\"]*)\"[^\>]*\>")
   219     XSD_STRING_MODEL = re.compile(r"<xsd\:(?:element|attribute) name=\"([^\"]*)\"[^\>]*\>")
   218     processCustomFiles(filelist, fileout, XSD_STRING_MODEL, 'Extra XSD strings')
   220     processCustomFiles(filelist, fileout, XSD_STRING_MODEL, 'Extra XSD strings')
   219 
   221 
   220     XML_TC6_STRING_MODEL = re.compile("<documentation>\s*<xhtml\:p><!\[CDATA\[([^\]]*)\]\]></xhtml\:p>\s*</documentation>", re.MULTILINE | re.DOTALL)
   222     XML_TC6_STRING_MODEL = re.compile(r"<documentation>\s*<xhtml\:p><!\[CDATA\[([^\]]*)\]\]></xhtml\:p>\s*</documentation>", re.MULTILINE | re.DOTALL)
   221     processCustomFiles(filelist, fileout, XML_TC6_STRING_MODEL, 'Extra TC6 documentation strings')
   223     processCustomFiles(filelist, fileout, XML_TC6_STRING_MODEL, 'Extra TC6 documentation strings')
   222 
   224 
   223     # generate messages.po
   225     # generate messages.po
   224     cmd = 'msginit --no-wrap --no-translator -i %s -l en_US.UTF-8 -o messages.po' % (fileout)
   226     cmd = 'msginit --no-wrap --no-translator -i %s -l en_US.UTF-8 -o messages.po' % (fileout)
   225     verbosePrint(verbose, cmd)
   227     verbosePrint(verbose, cmd)
   485     }
   487     }
   486     exit_code = 1
   488     exit_code = 1
   487     try:
   489     try:
   488         optionList, pargs = getopt.getopt(sys.argv[1:], validOptions, validLongOptions)
   490         optionList, pargs = getopt.getopt(sys.argv[1:], validOptions, validLongOptions)
   489     except getopt.GetoptError as e:
   491     except getopt.GetoptError as e:
   490         printUsage(e[0])
   492         printUsage(e)
   491         sys.exit(1)
   493         sys.exit(1)
   492     for (opt, val) in optionList:
   494     for (opt, val) in optionList:
   493         if opt == '-h':
   495         if opt == '-h':
   494             printUsage()
   496             printUsage()
   495             sys.exit(0)
   497             sys.exit(0)
   511     if option['po']:
   513     if option['po']:
   512         try:
   514         try:
   513             makePO(appDirPath, option['domain'], option['verbose'])
   515             makePO(appDirPath, option['domain'], option['verbose'])
   514             exit_code = 0
   516             exit_code = 0
   515         except IOError as e:
   517         except IOError as e:
   516             printUsage(e[1] + '\n   You must write a file app.fil that contains the list of all files to parse.')
   518             printUsage(text(e) + '\n   You must write a file app.fil that contains the list of all files to parse.')
   517     if option['mo']:
   519     if option['mo']:
   518         makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish'])
   520         makeMO(appDirPath, option['moTarget'], option['domain'], option['verbose'], option['forceEnglish'])
   519         exit_code = 0
   521         exit_code = 0
   520     sys.exit(exit_code)
   522     sys.exit(exit_code)
   521 
   523