babel.messages.frontend
Frontends for the message extraction functionality.
compile_catalog
Catalog compilation command for use in setup.py scripts.
If correctly installed, this command is available to Setuptools-using setup scripts automatically. For projects using plain old distutils, the command needs to be registered explicitly in setup.py:
from babel.messages.frontend import compile_catalog setup( ... cmdclass = {'compile_catalog': compile_catalog} )since: version 0.9 see: Integrating new distutils commands see: setuptools initialize_options(self)(Not documented)
finalize_options(self)(Not documented)
run(self)(Not documented)
extract_messages
Message extraction command for use in setup.py scripts.
If correctly installed, this command is available to Setuptools-using setup scripts automatically. For projects using plain old distutils, the command needs to be registered explicitly in setup.py:
from babel.messages.frontend import extract_messages setup( ... cmdclass = {'extract_messages': extract_messages} )see: Integrating new distutils commands see: setuptools initialize_options(self)(Not documented)
finalize_options(self)(Not documented)
run(self)(Not documented)
check_message_extractors(dist, name, value)Validate the message_extractors keyword argument to setup().
param dist: the distutils/setuptools Distribution object param name: the name of the keyword argument (should always be "message_extractors") param value: the value of the keyword argument raise DistutilsSetupError: if the value is not valid see: Adding setup() arguments init_catalog
New catalog initialization command for use in setup.py scripts.
If correctly installed, this command is available to Setuptools-using setup scripts automatically. For projects using plain old distutils, the command needs to be registered explicitly in setup.py:
from babel.messages.frontend import init_catalog setup( ... cmdclass = {'init_catalog': init_catalog} )see: Integrating new distutils commands see: setuptools initialize_options(self)(Not documented)
finalize_options(self)(Not documented)
run(self)(Not documented)
update_catalog
Catalog merging command for use in setup.py scripts.
If correctly installed, this command is available to Setuptools-using setup scripts automatically. For projects using plain old distutils, the command needs to be registered explicitly in setup.py:
from babel.messages.frontend import update_catalog setup( ... cmdclass = {'update_catalog': update_catalog} )since: version 0.9 see: Integrating new distutils commands see: setuptools initialize_options(self)(Not documented)
finalize_options(self)(Not documented)
run(self)(Not documented)
CommandLineInterface
Command-line interface.
This class provides a simple command-line interface to the message extraction and PO file generation functionality.
run(self, argv=sysargv)Main entry point of the command-line interface.
param argv: list of arguments passed on the command-line compile(self, argv)Subcommand for compiling a message catalog to a MO file.
param argv: the command arguments since: version 0.9 extract(self, argv)Subcommand for extracting messages from source files and generating a POT file.
param argv: the command arguments init(self, argv)Subcommand for creating new message catalogs from a template.
param argv: the command arguments update(self, argv)Subcommand for updating existing message catalogs from a template.
param argv: the command arguments since: version 0.9
main()(Not documented)
parse_mapping(fileobj, filename=None)Parse an extraction method mapping from a file-like object.
>>> buf = StringIO(''' ... [extractors] ... custom = mypackage.module:myfunc ... ... # Python source files ... [python: **.py] ... ... # Genshi templates ... [genshi: **/templates/**.html] ... include_attrs = ... [genshi: **/templates/**.txt] ... template_class = genshi.template:TextTemplate ... encoding = latin-1 ... ... # Some custom extractor ... [custom: **/custom/*.*] ... ''')>>> method_map, options_map = parse_mapping(buf) >>> len(method_map) 4
>>> method_map[0] ('**.py', 'python') >>> options_map['**.py'] {} >>> method_map[1] ('**/templates/**.html', 'genshi') >>> options_map['**/templates/**.html']['include_attrs'] '' >>> method_map[2] ('**/templates/**.txt', 'genshi') >>> options_map['**/templates/**.txt']['template_class'] 'genshi.template:TextTemplate' >>> options_map['**/templates/**.txt']['encoding'] 'latin-1'>>> method_map[3] ('**/custom/*.*', 'mypackage.module:myfunc') >>> options_map['**/custom/*.*'] {}param fileobj: a readable file-like object containing the configuration text to parse return: a (method_map, options_map) tuple rtype: tuple see: extract_from_directory parse_keywords(strings=)Parse keywords specifications from the given list of strings.
>>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3']) >>> for keyword, indices in sorted(kw.items()): ... print (keyword, indices) ('_', None) ('dgettext', (2,)) ('dngettext', (2, 3))
See ApiDocs, Documentation
