def makeXulPO(applicationDirectoryPath, applicationDomain=None, verbose=0): """Searches through xul files and appends to messages.pot""" if verbose: print "Importing xul templates..." path = Path(applicationDirectoryPath) messages = pot2dict('exe/locale/messages.pot') messageCommentTemplate = '\n#: %s:%s\nmsgid "' seq = len(messages) skipPaths = ( applicationDirectoryPath/'exe/webui/firefox', ) for fn in path.walkfiles(): if fn.ext.lower() == '.xul': for skipPath in skipPaths: if fn.startswith(skipPath): print 'IGNORING', fn break else: if verbose: print "template: ", fn reader = Sax2.Reader() doc = reader.fromStream(file(fn, 'rb')) xul2dict(doc, messages, seq, fn.relpath()) pot = Path('exe/locale/messages.pot') if pot.exists(): pot.remove() pot.touch() dict2pot(messages, 'exe/locale/messages.pot')
def makeXulPO(applicationDirectoryPath, applicationDomain=None, verbose=0): """Searches through xul files and appends to messages.pot""" if verbose: print "Importing xul templates..." path = Path(applicationDirectoryPath) messages = pot2dict('exe/locale/messages.pot') messageCommentTemplate = '\n#: %s:%s\nmsgid "' seq = len(messages) skipPaths = (applicationDirectoryPath / 'exe/webui/firefox', ) for fn in path.walkfiles(): if fn.ext.lower() == '.xul': for skipPath in skipPaths: if fn.startswith(skipPath): print 'IGNORING', fn break else: if verbose: print "template: ", fn reader = Sax2.Reader() doc = reader.fromStream(file(fn, 'rb')) xul2dict(doc, messages, seq, fn.relpath()) pot = Path('exe/locale/messages.pot') if pot.exists(): pot.remove() pot.touch() dict2pot(messages, 'exe/locale/messages.pot')
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1) : """Build the Portable Object Template file for the application. makePO builds the .pot file for the application stored inside a specified directory by running xgettext for all application source files. It finds the name of all files by looking for a file called 'app.fil'. If this file does not exists, makePo raises an IOError exception. By default the application domain (the application name) is the same as the directory name but it can be overridden by the 'applicationDomain' argument. makePO always creates a new file called messages.pot. If it finds files of the form app_xx.po where 'app' is the application name and 'xx' is one of the ISO 639 two-letter language codes, makePO resynchronizes those files with the latest extracted strings (now contained in messages.pot). This process updates all line location number in the language-specific .po files and may also create new entries for translation (or comment out some). The .po file is not changed, instead a new file is created with the .new extension appended to the name of the .po file. By default the function does not display what it is doing. Set the verbose argument to 1 to force it to print its commands. """ if applicationDomain is None: applicationName = fileBaseOf(applicationDirectoryPath,withPath=0) else: applicationName = applicationDomain currentDir = os.getcwd() messages_pot = Path('exe/locale/messages.pot') # Use xgettext to make the base messages.pot (with header, etc.) if messages_pot.exists(): messages_pot.remove() messages_pot.touch() cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 exe/engine/package.py' if verbose: print cmd os.system(cmd) if not os.path.exists('app.fil'): raise IOError(2,'No module file: app.fil') # Steps: # Use xgettext to parse all application modules # The following switches are used: # # -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 -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 %s' if verbose: print cmd for fn in open('app.fil'): print 'Extracting from', fn, os.system(cmd % fn[:-1]) makeXulPO(applicationDirectoryPath, applicationDomain, verbose) # Merge new pot with .po files localeDirs = Path('exe/locale') for filename in localeDirs.walkfiles('*_*.po'): cmd = "msgmerge -U --no-wrap %s exe/locale/messages.pot" % filename if verbose: print cmd os.system(cmd)
def makePO(applicationDirectoryPath, applicationDomain=None, verbose=1): """Build the Portable Object Template file for the application. makePO builds the .pot file for the application stored inside a specified directory by running xgettext for all application source files. It finds the name of all files by looking for a file called 'app.fil'. If this file does not exists, makePo raises an IOError exception. By default the application domain (the application name) is the same as the directory name but it can be overridden by the 'applicationDomain' argument. makePO always creates a new file called messages.pot. If it finds files of the form app_xx.po where 'app' is the application name and 'xx' is one of the ISO 639 two-letter language codes, makePO resynchronizes those files with the latest extracted strings (now contained in messages.pot). This process updates all line location number in the language-specific .po files and may also create new entries for translation (or comment out some). The .po file is not changed, instead a new file is created with the .new extension appended to the name of the .po file. By default the function does not display what it is doing. Set the verbose argument to 1 to force it to print its commands. """ if applicationDomain is None: applicationName = fileBaseOf(applicationDirectoryPath, withPath=0) else: applicationName = applicationDomain currentDir = os.getcwd() messages_pot = Path('exe/locale/messages.pot') # Use xgettext to make the base messages.pot (with header, etc.) if messages_pot.exists(): messages_pot.remove() messages_pot.touch() cmd = 'xgettext -kx_ -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 exe/engine/package.py' if verbose: print cmd os.system(cmd) if not os.path.exists('app.fil'): raise IOError(2, 'No module file: app.fil') # Steps: # Use xgettext to parse all application modules # The following switches are used: # # -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 -kx_ -L Python -s -j --no-wrap --output=exe/locale/messages.pot --from-code=utf8 %s' if verbose: print cmd for fn in open('app.fil'): print 'Extracting from', fn, os.system(cmd % fn[:-1]) makeXulPO(applicationDirectoryPath, applicationDomain, verbose) # Merge new pot with .po files localeDirs = Path('exe/locale') for filename in localeDirs.walkfiles('*_*.po'): cmd = "msgmerge -U --no-wrap -N %s exe/locale/messages.pot" % filename if verbose: print cmd os.system(cmd)