Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fluentogram/stub_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion fluentogram/stub_generator/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...""",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tests/assets/reference_with_args.ftl
Original file line number Diff line number Diff line change
@@ -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 }
11 changes: 11 additions & 0 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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