comments[:] = map(_strip, comments)
-def extract_from_dir(dirname=os.getcwd(), method_map=DEFAULT_MAPPING,
+def extract_from_dir(dirname=None, method_map=DEFAULT_MAPPING,
options_map=None, keywords=DEFAULT_KEYWORDS,
comment_tags=(), callback=None, strip_comment_tags=False):
"""Extract messages from any source files found in the given directory.
- This function generates tuples of the form:
-
- ``(filename, lineno, message, comments, context)``
+ 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.
... }
... }
- :param dirname: the path to the directory to extract messages from
+ :param dirname: the path to the directory to extract messages from. If
+ not given the current working directory is used.
:param method_map: a list of ``(pattern, method)`` tuples that maps of
extraction method names to extended glob patterns
:param options_map: a dictionary of additional options (optional)
tags to be removed from the collected comments.
:see: `pathmatch`
"""
+ if dirname is None:
+ dirname = os.getcwd()
if options_map is None:
options_map = {}
comment_tags=(), options=None, strip_comment_tags=False):
"""Extract messages from a specific file.
- This function returns a list of tuples of the form:
-
- ``(lineno, funcname, message)``
+ This function returns a list of tuples of the form ``(lineno, funcname,
+ message)``.
:param filename: the path to the file to extract messages from
:param method: a string specifying the extraction method (.e.g. "python")
"""Extract messages from the given file-like object using the specified
extraction method.
- This function returns tuples of the form:
-
- ``(lineno, message, comments)``
+ 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.
def extract_python(fileobj, keywords, comment_tags, options):
"""Extract messages from Python source code.
- It returns an iterator yielding tuples in the following form::
-
- (lineno, funcname, message, comments)
+ It returns an iterator yielding tuples in the following form ``(lineno,
+ funcname, message, comments)``.
:param fileobj: the seekable, file-like object the messages should be
extracted from
--- /dev/null
+Low-Level Extraction Interface
+==============================
+
+.. module:: babel.messages.extract
+
+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.
+
+Extraction Functions
+--------------------
+
+The extraction functions are what the command line tools use internally to
+extract strings.
+
+.. autofunction:: extract_from_dir
+
+.. autofunction:: extract_from_file
+
+.. autofunction:: extract
+
+Language Parsing
+----------------
+
+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.
+
+.. autofunction:: extract_python
+
+.. autofunction:: extract_javascript
+
+.. autofunction:: extract_nothing