Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n groundwork #155

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
78 changes: 77 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ safe_licenses = [
"GPLv2 with linking exception",
"MIT License",
"Mozilla Public License 2.0 (MPL 2.0)", # needs mention in license notices
"Python Software Foundation License",
]


Expand All @@ -61,6 +62,7 @@ python = ">=3.11"

arpy = "^2.3.0"
certifi = "^2024.2"
fluent-runtime = "^0.4.0"
jinja2 = "^3"
packaging = "^24.0"
pygit2 = "^1.14.0"
Expand Down
Empty file added ruyi/i18n/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions ruyi/i18n/fluent_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Generator

from fluent.runtime import AbstractResourceLoader
from fluent.syntax import FluentParser
from fluent.syntax.ast import Resource


class PrebuiltFluentResourceLoader(AbstractResourceLoader):
def __init__(self, data: dict[str, str]) -> None:
self._data = data

@classmethod
def _resource_key(cls, resource_id: str, locale: str) -> str:
return f"{resource_id}@{locale}"

def resources(
self,
locale: str,
resource_ids: list[str],
) -> Generator[list[Resource], None, None]:
resources: list[Resource] = []
for resource_id in resource_ids:
# combine resource_id and locale
if content := self._data.get(self._resource_key(resource_id, locale)):
resources.append(FluentParser().parse(content))
if resources:
yield resources
6 changes: 2 additions & 4 deletions ruyi/log/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import io
import time
from typing import Any, IO, Optional
import sys
import time
from typing import Any

from rich.console import Console, ConsoleRenderable
from rich.text import Text
Expand Down Expand Up @@ -120,8 +120,6 @@ def I( # noqa: E743 # the name intentionally mimics Android logging for brevity
*objects: Any,
sep: str = " ",
end: str = "\n",
file: Optional[IO[str]] = None,
flush: bool = False,
) -> None:
if is_porcelain():
return _emit_porcelain_log("I", message, sep, *objects)
Expand Down