.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.babel_extract Namespace Reference

Functions

 extract (fileobj, keywords, comment_tags, options)
 

Variables

str SEARXNG_MSG_FILE = "searxng.msg"
 
list _MSG_FILES = [path.join(path.dirname(__file__), SEARXNG_MSG_FILE)]
 

Detailed Description

This module implements the :origin:`searxng_msg <babel.cfg>` extractor to
extract messages from:

- :origin:`searx/searxng.msg`

The ``searxng.msg`` files are selected by Babel_, see Babel's configuration in
:origin:`babel.cfg`::

    searxng_msg = searx.babel_extract.extract
    ...
    [searxng_msg: **/searxng.msg]

A ``searxng.msg`` file is a python file that is *executed* by the
:py:obj:`extract` function.  Additional ``searxng.msg`` files can be added by:

1. Adding a ``searxng.msg`` file in one of the SearXNG python packages and
2. implement a method in :py:obj:`extract` that yields messages from this file.

.. _Babel: https://babel.pocoo.org/en/latest/index.html

Function Documentation

◆ extract()

searx.babel_extract.extract ( fileobj,
keywords,
comment_tags,
options )
Extract messages from ``searxng.msg`` files by a custom extractor_.

.. _extractor:
   https://babel.pocoo.org/en/latest/messages.html#writing-extraction-methods

Definition at line 30 of file babel_extract.py.

36):
37 """Extract messages from ``searxng.msg`` files by a custom extractor_.
38
39 .. _extractor:
40 https://babel.pocoo.org/en/latest/messages.html#writing-extraction-methods
41 """
42 if fileobj.name not in _MSG_FILES:
43 raise RuntimeError("don't know how to extract messages from %s" % fileobj.name)
44
45 namespace = {}
46 exec(fileobj.read(), {}, namespace) # pylint: disable=exec-used
47
48 for name in namespace['__all__']:
49 for k, v in namespace[name].items():
50 yield 0, '_', v, ["%s['%s']" % (name, k)]

Variable Documentation

◆ _MSG_FILES

list searx.babel_extract._MSG_FILES = [path.join(path.dirname(__file__), SEARXNG_MSG_FILE)]
protected

Definition at line 27 of file babel_extract.py.

◆ SEARXNG_MSG_FILE

str searx.babel_extract.SEARXNG_MSG_FILE = "searxng.msg"

Definition at line 26 of file babel_extract.py.