The low level extraction interface can be used to extract from directories or files directly. Normally this is not needed as the command line tools can do that for you.
The extraction functions are what the command line tools use internally to extract strings.
Extract messages from any source files found in the given directory.
This function generates tuples of the form (filename, lineno, message, comments, context).
Which extraction method is used per file is determined by the method_map parameter, which maps extended glob patterns to extraction method names. For example, the following is the default mapping:
>>> method_map = [
... ('**.py', 'python')
... ]
This basically says that files with the filename extension ”.py” at any level inside the directory should be processed by the “python” extraction method. Files that don’t match any of the mapping patterns are ignored. See the documentation of the pathmatch function for details on the pattern syntax.
The following extended mapping would also use the “genshi” extraction method on any file in “templates” subdirectory:
>>> method_map = [
... ('**/templates/**.*', 'genshi'),
... ('**.py', 'python')
... ]
The dictionary provided by the optional options_map parameter augments these mappings. It uses extended glob patterns as keys, and the values are dictionaries mapping options names to option values (both strings).
The glob patterns of the options_map do not necessarily need to be the same as those used in the method mapping. For example, while all files in the templates folders in an application may be Genshi applications, the options for those files may differ based on extension:
>>> options_map = {
... '**/templates/**.txt': {
... 'template_class': 'genshi.template:TextTemplate',
... 'encoding': 'latin-1'
... },
... '**/templates/**.html': {
... 'include_attrs': ''
... }
... }
Parameters: |
|
---|---|
See : | pathmatch |
Extract messages from a specific file.
This function returns a list of tuples of the form (lineno, funcname, message).
Parameters: |
|
---|
Extract messages from the given file-like object using the specified extraction method.
This function returns tuples of the form (lineno, message, comments).
The implementation dispatches the actual extraction to plugins, based on the value of the method parameter.
>>> source = '''# foo module
... def run(argv):
... print _('Hello, world!')
... '''
>>> from StringIO import StringIO
>>> for message in extract('python', StringIO(source)):
... print message
(3, u'Hello, world!', [], None)
Parameters: |
|
---|---|
Raises ValueError: | |
if the extraction method is not registered |
The language parsing functions are used to extract strings out of source files. These are automatically being used by the extraction functions but sometimes it can be useful to register wrapper functions, then these low level functions can be invoked.
New functions can be registered through the setuptools entrypoint system.
Extract messages from Python source code.
It returns an iterator yielding tuples in the following form (lineno, funcname, message, comments).
Parameters: |
|
---|---|
Return type: | iterator |
Extract messages from JavaScript source code.
Parameters: |
|
---|
Pseudo extractor that does not actually extract anything, but simply returns an empty list.