diff --git a/fluentogram/stub_generator/parser.py b/fluentogram/stub_generator/parser.py index 8bbfa7a..17b0780 100644 --- a/fluentogram/stub_generator/parser.py +++ b/fluentogram/stub_generator/parser.py @@ -46,6 +46,10 @@ def _parse_message_reference(self, message_obj: Message, element: ast.MessageRef # If the referenced message hasn't been processed yet, process it now self._process_message_elements(referenced_message) message_obj.result_text += referenced_message.result_text + # Add placeholders from referenced message, preserving order and avoiding duplicates + for placeholder in referenced_message.placeholders: + if placeholder not in message_obj.placeholders: + message_obj.placeholders.append(placeholder) else: logger.warning("Message reference %s not found", element.id.name) diff --git a/fluentogram/stub_generator/templates.py b/fluentogram/stub_generator/templates.py index df4f0db..2b5031f 100644 --- a/fluentogram/stub_generator/templates.py +++ b/fluentogram/stub_generator/templates.py @@ -104,9 +104,10 @@ class Runner(Class): """from decimal import Decimal from typing import Literal +from fluent_compiler.types import FluentType from typing_extensions import TypeAlias -PossibleValue: TypeAlias = str | int | float | Decimal | bool +PossibleValue: TypeAlias = str | int | float | Decimal | bool | FluentType class {{ class_name }}: def get(self, path: str, **kwargs: PossibleValue) -> str: ...""", diff --git a/pyproject.toml b/pyproject.toml index 7817ccf..38de396 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "fluentogram" -version = "1.2.0" +version = "1.2.1" description = "Fluentogram is easy way to use i18n (Fluent) mechanism in any python app." authors = [{ name = "Aleks" }] requires-python = ">=3.9" diff --git a/tests/assets/reference_with_args.ftl b/tests/assets/reference_with_args.ftl new file mode 100644 index 0000000..1018e66 --- /dev/null +++ b/tests/assets/reference_with_args.ftl @@ -0,0 +1,8 @@ +message-wth-placeholders = { $first_arg } { $second_arg } { $third_arg } + +just-another-text = just another text + +test-message = + { message-wth-placeholders } + + { just-another-text } diff --git a/tests/test_generator.py b/tests/test_generator.py index 69d8b60..5fbf4b8 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -91,3 +91,14 @@ def test_generator_if_conflict_in_prefix() -> None: assert "class AnotherUnknown" in content assert 'def error() -> Literal["""first-unknown-error"""]: ...' in content assert 'def error() -> Literal["""another-unknown-error"""]: ...' in content + + +def test_generator_if_reference_with_args() -> None: + with tempfile.NamedTemporaryFile(suffix=".pyi", delete=False) as tmp_file: + output_path = tmp_file.name + + generate(output_path, file_path="tests/assets/reference_with_args.ftl") + + assert Path(output_path).exists() + content = Path(output_path).read_text() + assert "def message(*, first_arg: PossibleValue, second_arg: PossibleValue, third_arg: PossibleValue)" in content