xcomponent 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xcomponent-0.7.0 → xcomponent-0.8.0}/CHANGELOG.md +4 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/Cargo.lock +1 -1
- {xcomponent-0.7.0 → xcomponent-0.8.0}/Cargo.toml +1 -1
- {xcomponent-0.7.0 → xcomponent-0.8.0}/Justfile +11 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/PKG-INFO +1 -1
- {xcomponent-0.7.0 → xcomponent-0.8.0}/pyproject.toml +6 -1
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/python/xcomponent/__init__.py +2 -1
- xcomponent-0.8.0/src/python/xcomponent/adapters/babel.py +154 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/python/xcomponent/xcore.pyi +17 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/ast/mod.rs +1 -1
- xcomponent-0.8.0/src/rust/expression/i18n.rs +282 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/mod.rs +1 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/lib.rs +3 -0
- xcomponent-0.8.0/tests/functionals/__init__.py +0 -0
- xcomponent-0.8.0/tests/functionals/i18n/__init__.py +0 -0
- xcomponent-0.8.0/tests/functionals/i18n/babel.ini +5 -0
- xcomponent-0.8.0/tests/functionals/i18n/fr.mo +0 -0
- xcomponent-0.8.0/tests/functionals/i18n/fr.po +39 -0
- xcomponent-0.8.0/tests/functionals/i18n/mydomain.pot +0 -0
- xcomponent-0.8.0/tests/functionals/i18n/test_l10n.py +84 -0
- xcomponent-0.8.0/tests/unittests/__init__.py +0 -0
- xcomponent-0.8.0/tests/unittests/adapters/__init__.py +0 -0
- xcomponent-0.8.0/tests/unittests/adapters/test_babel.py +230 -0
- xcomponent-0.8.0/uv.lock +1462 -0
- xcomponent-0.7.0/uv.lock +0 -649
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/build-sdist.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/build-wheels.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/publish-doc.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/publish-pypi.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/release.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/tests-artifacts.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.github/workflows/tests.yml +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.gitignore +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/.python-version +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/LICENSE +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/README.md +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/Makefile +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/source/conf.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/source/develop/.gitkeep +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/source/index.md +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/source/user/changelog.md +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/docs/source/user/getting_started.md +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/scripts/get_version.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/scripts/write_changelog.py +0 -0
- {xcomponent-0.7.0/src/python/xcomponent/service → xcomponent-0.8.0/src/python/xcomponent/adapters}/__init__.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/python/xcomponent/py.typed +0 -0
- {xcomponent-0.7.0/tests → xcomponent-0.8.0/src/python/xcomponent/service}/__init__.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/python/xcomponent/service/catalog.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/catalog/catalog.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/catalog/mod.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/context.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/ast/eval.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/ast/model.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/ast/parse.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/grammar.pest +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/parser.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/expression/tokens.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/markup/grammar.pest +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/markup/mod.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/markup/parser.rs +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/src/rust/markup/tokens.rs +0 -0
- {xcomponent-0.7.0/tests/unittests → xcomponent-0.8.0/tests}/__init__.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/conftest.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_binary_eq.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_binary_op.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_binary_op_bool.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_default_values.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_field_access.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_for_expr.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_func.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_if_expr.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_let.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_nested.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_render_comment.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_script.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_str_dedent.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_str_method.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_types.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/expression/test_unary.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_core.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_named_component.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_attributes.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_context.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_globals.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_globals_obj.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_globals_obj2.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_nested_dict.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_nested_node.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_node.py +0 -0
- {xcomponent-0.7.0 → xcomponent-0.8.0}/tests/unittests/test_render_script.py +0 -0
|
@@ -26,6 +26,17 @@ cleandoc:
|
|
|
26
26
|
|
|
27
27
|
test: lint typecheck unittest
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
functest_update_catalog:
|
|
31
|
+
uv run pybabel extract --keyword dpgettext:2c,3 --keyword dnpgettext:2c,3,4 -F tests/functionals/i18n/babel.ini --input-dirs tests/functionals/ -o tests/functionals/i18n/mydomain.pot
|
|
32
|
+
# uv run pybabel init -D mydomain -i tests/functionals/i18n/mydomain.pot -l fr -o tests/functionals/i18n/fr.po
|
|
33
|
+
# uv run pybabel
|
|
34
|
+
uv run pybabel update -d mydomain -i tests/functionals/i18n/mydomain.pot -l fr -o tests/functionals/i18n/fr.po
|
|
35
|
+
uv run pybabel compile -l fr -D mydomain -i tests/functionals/i18n/fr.po -o tests/functionals/i18n/fr.mo
|
|
36
|
+
|
|
37
|
+
functest: functest_update_catalog
|
|
38
|
+
uv run pytest tests/functionals
|
|
39
|
+
|
|
29
40
|
lint:
|
|
30
41
|
uv run ruff check .
|
|
31
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "xcomponent"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.8.0"
|
|
4
4
|
description = "An embeded component base template engine - inspired by JSX"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Guillaume Gauvrit", email = "guillaume@gauvr.it" }]
|
|
@@ -40,7 +40,9 @@ docs = [
|
|
|
40
40
|
|
|
41
41
|
[dependency-groups]
|
|
42
42
|
dev = [
|
|
43
|
+
"babel (>=2.17.0,<3.0.0)",
|
|
43
44
|
"bs4>=0.0.2",
|
|
45
|
+
"fastlifeweb >=0.28,<1",
|
|
44
46
|
"mypy >=1.16.0,<2",
|
|
45
47
|
"pytest >=8.3.5,<9",
|
|
46
48
|
]
|
|
@@ -52,6 +54,9 @@ docs = [
|
|
|
52
54
|
"sphinx-autodoc2 >=0.5.0,<1",
|
|
53
55
|
]
|
|
54
56
|
|
|
57
|
+
[project.entry-points."babel.extractors"]
|
|
58
|
+
xcomponent = "xcomponent.:extract_xcomponent"
|
|
59
|
+
|
|
55
60
|
[tool.pyright]
|
|
56
61
|
autoSearchPaths = false
|
|
57
62
|
extraPaths = ["src/python"]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from importlib import metadata
|
|
2
2
|
from xcomponent.service.catalog import Catalog, Component, Function
|
|
3
3
|
from xcomponent.xcore import XNode
|
|
4
|
+
from xcomponent.adapters.babel import extract_xtemplate
|
|
4
5
|
|
|
5
|
-
__all__ = ["Catalog", "Component", "Function", "XNode"]
|
|
6
|
+
__all__ = ["Catalog", "Component", "Function", "XNode", "extract_xtemplate"]
|
|
6
7
|
__version__ = metadata.version("xcomponent")
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from tokenize import STRING, generate_tokens
|
|
3
|
+
from typing import Any, BinaryIO
|
|
4
|
+
|
|
5
|
+
from xcomponent import XNode
|
|
6
|
+
from xcomponent.xcore import (
|
|
7
|
+
XElement,
|
|
8
|
+
XExpression,
|
|
9
|
+
XFragment,
|
|
10
|
+
extract_expr_i18n_messages,
|
|
11
|
+
parse_markup,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
lineno = int
|
|
16
|
+
funcname = str
|
|
17
|
+
message = Any
|
|
18
|
+
comments = list[str]
|
|
19
|
+
ExtractionInfo = tuple[lineno, funcname, message, comments]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def extract_from_markup(node: XNode, offset: int) -> Iterator[ExtractionInfo]:
|
|
23
|
+
match node.unwrap():
|
|
24
|
+
case XFragment(children):
|
|
25
|
+
for child in children:
|
|
26
|
+
for nfo in extract_from_markup(child, offset):
|
|
27
|
+
yield nfo
|
|
28
|
+
case XElement(_, attrs, children):
|
|
29
|
+
for child in attrs.values():
|
|
30
|
+
for nfo in extract_from_markup(child, offset):
|
|
31
|
+
yield nfo
|
|
32
|
+
for child in children:
|
|
33
|
+
for nfo in extract_from_markup(child, offset):
|
|
34
|
+
yield nfo
|
|
35
|
+
case XExpression(expr):
|
|
36
|
+
msgs = extract_expr_i18n_messages(expr)
|
|
37
|
+
for msg in msgs:
|
|
38
|
+
match msg.funcname:
|
|
39
|
+
case "gettext":
|
|
40
|
+
yield (
|
|
41
|
+
offset + msg.lineno,
|
|
42
|
+
msg.funcname,
|
|
43
|
+
msg.message.message,
|
|
44
|
+
msg.comments,
|
|
45
|
+
)
|
|
46
|
+
case "dgettext":
|
|
47
|
+
# what I do with the domain here ?
|
|
48
|
+
yield (
|
|
49
|
+
offset + msg.lineno,
|
|
50
|
+
msg.funcname,
|
|
51
|
+
(msg.message.domain, msg.message.message),
|
|
52
|
+
msg.comments,
|
|
53
|
+
)
|
|
54
|
+
case "ngettext":
|
|
55
|
+
yield (
|
|
56
|
+
offset + msg.lineno,
|
|
57
|
+
msg.funcname,
|
|
58
|
+
(msg.message.singular, msg.message.plural),
|
|
59
|
+
msg.comments,
|
|
60
|
+
)
|
|
61
|
+
case "dngettext":
|
|
62
|
+
# what I do with the domain here ?
|
|
63
|
+
yield (
|
|
64
|
+
offset + msg.lineno,
|
|
65
|
+
msg.funcname,
|
|
66
|
+
(
|
|
67
|
+
msg.message.domain,
|
|
68
|
+
msg.message.singular,
|
|
69
|
+
msg.message.plural,
|
|
70
|
+
),
|
|
71
|
+
msg.comments,
|
|
72
|
+
)
|
|
73
|
+
case "pgettext":
|
|
74
|
+
yield (
|
|
75
|
+
offset + msg.lineno,
|
|
76
|
+
msg.funcname,
|
|
77
|
+
(
|
|
78
|
+
msg.message.context,
|
|
79
|
+
msg.message.message,
|
|
80
|
+
),
|
|
81
|
+
msg.comments,
|
|
82
|
+
)
|
|
83
|
+
case "dpgettext":
|
|
84
|
+
yield (
|
|
85
|
+
offset + msg.lineno,
|
|
86
|
+
msg.funcname,
|
|
87
|
+
(
|
|
88
|
+
msg.message.domain,
|
|
89
|
+
msg.message.context,
|
|
90
|
+
msg.message.message,
|
|
91
|
+
),
|
|
92
|
+
msg.comments,
|
|
93
|
+
)
|
|
94
|
+
case "npgettext":
|
|
95
|
+
yield (
|
|
96
|
+
offset + msg.lineno,
|
|
97
|
+
msg.funcname,
|
|
98
|
+
(
|
|
99
|
+
msg.message.context,
|
|
100
|
+
msg.message.singular,
|
|
101
|
+
msg.message.plural,
|
|
102
|
+
),
|
|
103
|
+
msg.comments,
|
|
104
|
+
)
|
|
105
|
+
case "dnpgettext":
|
|
106
|
+
yield (
|
|
107
|
+
offset + msg.lineno,
|
|
108
|
+
msg.funcname,
|
|
109
|
+
(
|
|
110
|
+
msg.message.domain,
|
|
111
|
+
msg.message.context,
|
|
112
|
+
msg.message.singular,
|
|
113
|
+
msg.message.plural,
|
|
114
|
+
),
|
|
115
|
+
msg.comments,
|
|
116
|
+
)
|
|
117
|
+
case _:
|
|
118
|
+
...
|
|
119
|
+
case _:
|
|
120
|
+
pass
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def extract_xtemplate(
|
|
124
|
+
fileobj: BinaryIO,
|
|
125
|
+
keywords: list[str],
|
|
126
|
+
comment_tags: list[str],
|
|
127
|
+
options: dict[str, str],
|
|
128
|
+
) -> Iterator[ExtractionInfo]:
|
|
129
|
+
"""
|
|
130
|
+
Extract messages from a xcomponent templates in python file.
|
|
131
|
+
|
|
132
|
+
:param fileobj: the file-like object the messages should be extracted
|
|
133
|
+
from
|
|
134
|
+
:param keywords: a list of keywords (i.e. function names) that should
|
|
135
|
+
be recognized as translation functions
|
|
136
|
+
:param comment_tags: a list of translator tags to search for and
|
|
137
|
+
include in the results
|
|
138
|
+
:param options: a dictionary of additional options (optional)
|
|
139
|
+
:return: an iterator over ``(lineno, funcname, message, comments)``
|
|
140
|
+
tuples
|
|
141
|
+
:rtype: ``iterator``
|
|
142
|
+
"""
|
|
143
|
+
encoding = options.get("encoding", "UTF-8")
|
|
144
|
+
|
|
145
|
+
def next_line():
|
|
146
|
+
return fileobj.readline().decode(encoding)
|
|
147
|
+
|
|
148
|
+
tokens = generate_tokens(next_line)
|
|
149
|
+
|
|
150
|
+
for tok, value, (lineno, _), _, _ in tokens:
|
|
151
|
+
if tok == STRING:
|
|
152
|
+
markup = parse_markup(f"<>{value}</>")
|
|
153
|
+
for messageinfo in extract_from_markup(markup, lineno):
|
|
154
|
+
yield messageinfo
|
|
@@ -61,6 +61,7 @@ class XExpression:
|
|
|
61
61
|
|
|
62
62
|
class XNode:
|
|
63
63
|
"""Represent a node in the markup."""
|
|
64
|
+
|
|
64
65
|
@staticmethod
|
|
65
66
|
def Fragment(fragment: XFragment, /) -> XNode: ...
|
|
66
67
|
@staticmethod
|
|
@@ -79,6 +80,21 @@ class XNode:
|
|
|
79
80
|
def __eq__(self, other: object) -> bool: ...
|
|
80
81
|
def unwrap(self) -> XFragment | XElement | XComment | XText | XExpression: ...
|
|
81
82
|
|
|
83
|
+
def parse_markup(raw: str) -> XNode:
|
|
84
|
+
"""
|
|
85
|
+
Parse the given markup and return the root XNode.
|
|
86
|
+
|
|
87
|
+
If the raw template is not valid, then a ValueError exception is raised,
|
|
88
|
+
with an invalid markup hint message.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def extract_expr_i18n_messages(
|
|
92
|
+
raw: str,
|
|
93
|
+
) -> list[Any]:
|
|
94
|
+
"""
|
|
95
|
+
Used for i18n extraction message purpose.
|
|
96
|
+
"""
|
|
97
|
+
|
|
82
98
|
class XTemplate:
|
|
83
99
|
node: XNode
|
|
84
100
|
params: Mapping[str, type | Any]
|
|
@@ -86,6 +102,7 @@ class XTemplate:
|
|
|
86
102
|
|
|
87
103
|
class XCatalog:
|
|
88
104
|
"""Catalog of templates en functions."""
|
|
105
|
+
|
|
89
106
|
def __init__(self) -> None: ...
|
|
90
107
|
def add_component(
|
|
91
108
|
self,
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
use pyo3::{prelude::*, pyclass, pyfunction, pymethods, Bound, PyResult, Python};
|
|
2
|
+
|
|
3
|
+
use crate::{
|
|
4
|
+
context::Literal,
|
|
5
|
+
expression::{
|
|
6
|
+
ast::{model::AST, parse::parse},
|
|
7
|
+
parser::tokenize,
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
#[pyclass]
|
|
12
|
+
#[derive(Debug, Clone)]
|
|
13
|
+
pub enum MessageKind {
|
|
14
|
+
Gettext {
|
|
15
|
+
message: String,
|
|
16
|
+
},
|
|
17
|
+
Dgettext {
|
|
18
|
+
domain: String,
|
|
19
|
+
message: String,
|
|
20
|
+
},
|
|
21
|
+
Ngettext {
|
|
22
|
+
singular: String,
|
|
23
|
+
plural: String,
|
|
24
|
+
},
|
|
25
|
+
Dngettext {
|
|
26
|
+
domain: String,
|
|
27
|
+
singular: String,
|
|
28
|
+
plural: String,
|
|
29
|
+
},
|
|
30
|
+
Pgettext {
|
|
31
|
+
context: String,
|
|
32
|
+
message: String,
|
|
33
|
+
},
|
|
34
|
+
Dpgettext {
|
|
35
|
+
domain: String,
|
|
36
|
+
context: String,
|
|
37
|
+
message: String,
|
|
38
|
+
},
|
|
39
|
+
Npgettext {
|
|
40
|
+
context: String,
|
|
41
|
+
singular: String,
|
|
42
|
+
plural: String,
|
|
43
|
+
},
|
|
44
|
+
Dnpgettext {
|
|
45
|
+
domain: String,
|
|
46
|
+
context: String,
|
|
47
|
+
singular: String,
|
|
48
|
+
plural: String,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[pyclass]
|
|
53
|
+
#[derive(Debug, Clone)]
|
|
54
|
+
pub struct ExtractedMessage {
|
|
55
|
+
lineno: usize,
|
|
56
|
+
funcname: String,
|
|
57
|
+
message: MessageKind,
|
|
58
|
+
comments: Vec<String>,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl ExtractedMessage {
|
|
62
|
+
fn new(lineno: usize, funcname: String, message: MessageKind, comments: Vec<String>) -> Self {
|
|
63
|
+
ExtractedMessage {
|
|
64
|
+
lineno,
|
|
65
|
+
funcname,
|
|
66
|
+
message,
|
|
67
|
+
comments,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[pymethods]
|
|
73
|
+
impl ExtractedMessage {
|
|
74
|
+
#[getter]
|
|
75
|
+
pub fn lineno<'py>(&self) -> usize {
|
|
76
|
+
self.lineno
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[getter]
|
|
80
|
+
pub fn funcname<'py>(&self) -> &str {
|
|
81
|
+
self.funcname.as_str()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#[getter]
|
|
85
|
+
pub fn message<'py>(&self, py: Python<'py>) -> Bound<'py, PyAny> {
|
|
86
|
+
let c = self.message.clone().into_pyobject(py);
|
|
87
|
+
c.unwrap().into_any()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[getter]
|
|
91
|
+
pub fn comments<'py>(&self, py: Python<'py>) -> Bound<'py, PyAny> {
|
|
92
|
+
self.comments.clone().into_pyobject(py).unwrap()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fn extract_from_ast(ast: AST) -> Vec<ExtractedMessage> {
|
|
97
|
+
let mut res = Vec::new();
|
|
98
|
+
match ast {
|
|
99
|
+
AST::CallAccess {
|
|
100
|
+
left,
|
|
101
|
+
args,
|
|
102
|
+
kwargs: _,
|
|
103
|
+
} => match *left {
|
|
104
|
+
AST::FieldAccess(_, s) => match s.as_str() {
|
|
105
|
+
"gettext" => match args.first() {
|
|
106
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
107
|
+
0,
|
|
108
|
+
s.clone(),
|
|
109
|
+
MessageKind::Gettext { message: v.clone() },
|
|
110
|
+
Vec::new(),
|
|
111
|
+
)),
|
|
112
|
+
_ => (),
|
|
113
|
+
},
|
|
114
|
+
"ngettext" => {
|
|
115
|
+
let singular = match args.first() {
|
|
116
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
117
|
+
_ => "".to_owned(),
|
|
118
|
+
};
|
|
119
|
+
match args.get(1) {
|
|
120
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
121
|
+
0,
|
|
122
|
+
s.clone(),
|
|
123
|
+
MessageKind::Ngettext {
|
|
124
|
+
singular,
|
|
125
|
+
plural: v.clone(),
|
|
126
|
+
},
|
|
127
|
+
Vec::new(),
|
|
128
|
+
)),
|
|
129
|
+
_ => (),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
"dgettext" => {
|
|
133
|
+
let domain = match args.first() {
|
|
134
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
135
|
+
_ => "".to_owned(),
|
|
136
|
+
};
|
|
137
|
+
match args.get(1) {
|
|
138
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
139
|
+
0,
|
|
140
|
+
s.clone(),
|
|
141
|
+
MessageKind::Dgettext {
|
|
142
|
+
domain,
|
|
143
|
+
message: v.clone(),
|
|
144
|
+
},
|
|
145
|
+
Vec::new(),
|
|
146
|
+
)),
|
|
147
|
+
_ => (),
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
"dngettext" => {
|
|
151
|
+
let domain = match args.first() {
|
|
152
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
153
|
+
_ => "".to_owned(),
|
|
154
|
+
};
|
|
155
|
+
let singular = match args.get(1) {
|
|
156
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
157
|
+
_ => "".to_owned(),
|
|
158
|
+
};
|
|
159
|
+
match args.get(2) {
|
|
160
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
161
|
+
0,
|
|
162
|
+
s.clone(),
|
|
163
|
+
MessageKind::Dngettext {
|
|
164
|
+
domain,
|
|
165
|
+
singular,
|
|
166
|
+
plural: v.clone(),
|
|
167
|
+
},
|
|
168
|
+
Vec::new(),
|
|
169
|
+
)),
|
|
170
|
+
_ => (),
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
"pgettext" => {
|
|
174
|
+
let context = match args.first() {
|
|
175
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
176
|
+
_ => "".to_owned(),
|
|
177
|
+
};
|
|
178
|
+
match args.get(1) {
|
|
179
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
180
|
+
0,
|
|
181
|
+
s.clone(),
|
|
182
|
+
MessageKind::Pgettext {
|
|
183
|
+
context,
|
|
184
|
+
message: v.clone(),
|
|
185
|
+
},
|
|
186
|
+
Vec::new(),
|
|
187
|
+
)),
|
|
188
|
+
_ => (),
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
"dpgettext" => {
|
|
192
|
+
let domain = match args.first() {
|
|
193
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
194
|
+
_ => "".to_owned(),
|
|
195
|
+
};
|
|
196
|
+
let context = match args.get(1) {
|
|
197
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
198
|
+
_ => "".to_owned(),
|
|
199
|
+
};
|
|
200
|
+
match args.get(2) {
|
|
201
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
202
|
+
0,
|
|
203
|
+
s.clone(),
|
|
204
|
+
MessageKind::Dpgettext {
|
|
205
|
+
domain,
|
|
206
|
+
context,
|
|
207
|
+
message: v.clone(),
|
|
208
|
+
},
|
|
209
|
+
Vec::new(),
|
|
210
|
+
)),
|
|
211
|
+
_ => (),
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
"npgettext" => {
|
|
215
|
+
let context = match args.first() {
|
|
216
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
217
|
+
_ => "".to_owned(),
|
|
218
|
+
};
|
|
219
|
+
let singular = match args.get(1) {
|
|
220
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
221
|
+
_ => "".to_owned(),
|
|
222
|
+
};
|
|
223
|
+
match args.get(2) {
|
|
224
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
225
|
+
0,
|
|
226
|
+
s.clone(),
|
|
227
|
+
MessageKind::Npgettext {
|
|
228
|
+
context,
|
|
229
|
+
singular,
|
|
230
|
+
plural: v.clone(),
|
|
231
|
+
},
|
|
232
|
+
Vec::new(),
|
|
233
|
+
)),
|
|
234
|
+
_ => (),
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
"dnpgettext" => {
|
|
238
|
+
let domain = match args.first() {
|
|
239
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
240
|
+
_ => "".to_owned(),
|
|
241
|
+
};
|
|
242
|
+
let context = match args.get(1) {
|
|
243
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
244
|
+
_ => "".to_owned(),
|
|
245
|
+
};
|
|
246
|
+
let singular = match args.get(2) {
|
|
247
|
+
Some(AST::Literal(Literal::Str(v))) => v.clone(),
|
|
248
|
+
_ => "".to_owned(),
|
|
249
|
+
};
|
|
250
|
+
match args.get(3) {
|
|
251
|
+
Some(AST::Literal(Literal::Str(v))) => res.push(ExtractedMessage::new(
|
|
252
|
+
0,
|
|
253
|
+
s.clone(),
|
|
254
|
+
MessageKind::Dnpgettext {
|
|
255
|
+
domain,
|
|
256
|
+
context,
|
|
257
|
+
singular,
|
|
258
|
+
plural: v.clone(),
|
|
259
|
+
},
|
|
260
|
+
Vec::new(),
|
|
261
|
+
)),
|
|
262
|
+
_ => (),
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
_ => {}
|
|
266
|
+
},
|
|
267
|
+
_ => {}
|
|
268
|
+
},
|
|
269
|
+
_ => {
|
|
270
|
+
warn!("Ignoring {:?} while extracting messages", ast);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
res
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#[pyfunction]
|
|
277
|
+
pub(crate) fn extract_expr_i18n_messages(raw: &str) -> PyResult<Vec<ExtractedMessage>> {
|
|
278
|
+
let token = tokenize(raw)?;
|
|
279
|
+
let ast = parse(&[token], 0)?;
|
|
280
|
+
|
|
281
|
+
Ok(extract_from_ast(ast))
|
|
282
|
+
}
|
|
@@ -15,6 +15,7 @@ mod markup;
|
|
|
15
15
|
|
|
16
16
|
use crate::catalog::XCatalog;
|
|
17
17
|
use crate::context::RenderContext;
|
|
18
|
+
use crate::expression::i18n::extract_expr_i18n_messages;
|
|
18
19
|
use crate::markup::parser::parse_markup;
|
|
19
20
|
use crate::markup::tokens::{NodeType, XComment, XElement, XExpression, XFragment, XNode, XText};
|
|
20
21
|
|
|
@@ -35,5 +36,7 @@ fn xcore(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
35
36
|
m.add_class::<RenderContext>()?;
|
|
36
37
|
|
|
37
38
|
m.add_function(wrap_pyfunction!(parse_markup, m)?)?;
|
|
39
|
+
m.add_function(wrap_pyfunction!(extract_expr_i18n_messages, m)?)?;
|
|
40
|
+
|
|
38
41
|
Ok(())
|
|
39
42
|
}
|
|
File without changes
|
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# French translations for PROJECT.
|
|
2
|
+
# Copyright (C) 2025 ORGANIZATION
|
|
3
|
+
# This file is distributed under the same license as the PROJECT project.
|
|
4
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
|
|
5
|
+
#
|
|
6
|
+
msgid ""
|
|
7
|
+
msgstr ""
|
|
8
|
+
"Project-Id-Version: PROJECT VERSION\n"
|
|
9
|
+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
|
|
10
|
+
"POT-Creation-Date: 2025-10-17 23:29+0200\n"
|
|
11
|
+
"PO-Revision-Date: 2025-10-17 23:18+0200\n"
|
|
12
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
13
|
+
"Language: fr\n"
|
|
14
|
+
"Language-Team: fr <LL@li.org>\n"
|
|
15
|
+
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
|
16
|
+
"MIME-Version: 1.0\n"
|
|
17
|
+
"Content-Type: text/plain; charset=utf-8\n"
|
|
18
|
+
"Content-Transfer-Encoding: 8bit\n"
|
|
19
|
+
"Generated-By: Babel 2.17.0\n"
|
|
20
|
+
|
|
21
|
+
#: tests/functionals/i18n/test_l10n.py:19
|
|
22
|
+
#: tests/functionals/i18n/test_l10n.py:24
|
|
23
|
+
#: tests/functionals/i18n/test_l10n.py:29
|
|
24
|
+
#: tests/functionals/i18n/test_l10n.py:34
|
|
25
|
+
msgid "The lazy dog"
|
|
26
|
+
msgid_plural "The lazy dogs"
|
|
27
|
+
msgstr[0] "Le chien fénéant"
|
|
28
|
+
msgstr[1] "Les chiens fénéants"
|
|
29
|
+
|
|
30
|
+
#: tests/functionals/i18n/test_l10n.py:41
|
|
31
|
+
#: tests/functionals/i18n/test_l10n.py:46
|
|
32
|
+
#: tests/functionals/i18n/test_l10n.py:51
|
|
33
|
+
#: tests/functionals/i18n/test_l10n.py:56
|
|
34
|
+
msgctxt "animal"
|
|
35
|
+
msgid "The lazy dog"
|
|
36
|
+
msgid_plural "The lazy dogs"
|
|
37
|
+
msgstr[0] "Le chien fénéant"
|
|
38
|
+
msgstr[1] "Les chiens fénéants"
|
|
39
|
+
|
|
File without changes
|