.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
babel_extract.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""This module implements the :origin:`searxng_msg <babel.cfg>` extractor to
3
extract messages from:
4
5
- :origin:`searx/searxng.msg`
6
7
The ``searxng.msg`` files are selected by Babel_, see Babel's configuration in
8
:origin:`babel.cfg`::
9
10
searxng_msg = searx.babel_extract.extract
11
...
12
[searxng_msg: **/searxng.msg]
13
14
A ``searxng.msg`` file is a python file that is *executed* by the
15
:py:obj:`extract` function. Additional ``searxng.msg`` files can be added by:
16
17
1. Adding a ``searxng.msg`` file in one of the SearXNG python packages and
18
2. implement a method in :py:obj:`extract` that yields messages from this file.
19
20
.. _Babel: https://babel.pocoo.org/en/latest/index.html
21
22
"""
23
24
from
os
import
path
25
26
SEARXNG_MSG_FILE =
"searxng.msg"
27
_MSG_FILES = [path.join(path.dirname(__file__), SEARXNG_MSG_FILE)]
28
29
30
def
extract
(
31
# pylint: disable=unused-argument
32
fileobj,
33
keywords,
34
comment_tags,
35
options,
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)]
searx.babel_extract.extract
extract(fileobj, keywords, comment_tags, options)
Definition
babel_extract.py:36
searxng
searx
babel_extract.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0