Skip to content

Commit 453855a

Browse files
committed
Merge branch 'main' into refactor/replace-codecs-open
2 parents 96d25f5 + addd1fc commit 453855a

36 files changed

Lines changed: 924 additions & 386 deletions

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
exclude=.tox
2+
exclude=.venv
33
extend-ignore = E203
44
max-line-length=120

.github/workflows/ci.yml

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,38 @@ on:
55
branches:
66
- main
77
pull_request:
8+
workflow_dispatch:
89

910
jobs:
1011
lint:
1112
runs-on: ubuntu-latest
1213
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-python@v5
14+
- uses: actions/checkout@v6
15+
- uses: astral-sh/setup-uv@v7
1516
with:
16-
cache: pip
17-
cache-dependency-path: |
18-
dev-requirements.txt
19-
fluent.syntax/setup.py
20-
fluent.runtime/setup.py
21-
- run: python -m pip install -r dev-requirements.txt
22-
- run: python -m pip install ./fluent.syntax ./fluent.runtime
23-
- run: python -m flake8
24-
- run: python -m mypy fluent.syntax/fluent fluent.runtime/fluent
17+
python-version: 3.9
18+
- uses: actions/setup-python@v6
19+
- run: uv sync --dev --all-packages
20+
- run: uv run python -m flake8
21+
- run: uv run mypy fluent.syntax/fluent fluent.runtime/fluent
2522
test:
2623
runs-on: ${{ matrix.os }}
2724
strategy:
2825
matrix:
29-
os: [ubuntu-22.04, windows-2022]
30-
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12, pypy3.9, pypy3.10]
26+
os: [ubuntu-latest, windows-latest, macos-latest]
27+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
3128
steps:
32-
- uses: actions/checkout@v4
33-
- uses: actions/setup-python@v5
29+
- uses: actions/checkout@v6
30+
- uses: astral-sh/setup-uv@v7
3431
with:
3532
python-version: ${{ matrix.python-version }}
36-
cache: pip
37-
cache-dependency-path: |
38-
fluent.syntax/setup.py
39-
fluent.runtime/setup.py
40-
- run: python -m pip install ./fluent.syntax ./fluent.runtime
41-
- run: python -m unittest discover -s fluent.syntax
42-
- run: python -m unittest discover -s fluent.runtime
33+
- run: uv sync --dev --all-packages
34+
- run: uv run python -m unittest discover -s fluent.syntax
35+
- run: uv run python -m unittest discover -s fluent.runtime
4336

44-
# Test compatibility with the oldest Python version we claim to support,
45-
# and for fluent.runtime's compatibility with a range of fluent.syntax versions.
37+
# Test fluent.runtime's compatibility with a range of fluent.syntax versions.
4638
compatibility:
47-
runs-on: ubuntu-20.04 # https://github.com/actions/setup-python/issues/544
39+
runs-on: ubuntu-22.04
4840
strategy:
4941
matrix:
5042
fluent-syntax:
@@ -53,10 +45,11 @@ jobs:
5345
- fluent.syntax==0.18.1 six
5446
- fluent.syntax==0.17.0 six
5547
steps:
56-
- uses: actions/checkout@v3
57-
- uses: actions/setup-python@v4
48+
- uses: actions/checkout@v6
49+
- uses: astral-sh/setup-uv@v7
5850
with:
59-
python-version: 3.6
60-
- run: python -m pip install ${{ matrix.fluent-syntax }}
61-
- run: python -m pip install ./fluent.runtime
62-
- run: python -m unittest discover -s fluent.runtime
51+
python-version: 3.12
52+
- run: uv venv
53+
- run: uv pip install ${{ matrix.fluent-syntax }}
54+
- run: uv pip install ./fluent.runtime
55+
- run: uv run python -m unittest discover -s fluent.runtime

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.autoComplete.extraPaths": ["./fluent.syntax"],
3+
"python.analysis.extraPaths": ["./fluent.syntax"],
4+
"mypy-type-checker.ignorePatterns": ["**/tests/**"]
5+
}

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Project Fluent
2+
3+
This is a collection of Python packages to use the
4+
[Fluent localization system](http://projectfluent.org/):
5+
6+
## `fluent.syntax`
7+
8+
The [syntax package](./fluent.syntax) includes the
9+
parser, serializer, and traversal utilities like `Visitor` and `Transformer`.
10+
You’re looking for this package if you work on tooling for Fluent in Python.
11+
12+
## `fluent.runtime`
13+
14+
The [runtime package](./fluent.runtime) includes the library required to
15+
use Fluent to localize your Python application.
16+
It comes with a `Localization` class to use, based on an implementation of `FluentBundle`.
17+
It uses the tooling parser above to read Fluent files.
18+
19+
## `fluent.pygments`
20+
21+
A [plugin for pygments](./fluent.pygments) to add syntax highlighting to Sphinx.
22+
23+
## Discuss
24+
25+
We’d love to hear your thoughts on Project Fluent! Whether you’re a
26+
localizer looking for a better way to express yourself in your language,
27+
or a developer trying to make your app localizable and multilingual, or
28+
a hacker looking for a project to contribute to, please do get in touch
29+
on the mailing list and the IRC channel.
30+
31+
- Mozilla Discourse: https://discourse.mozilla.org/c/fluent
32+
- Matrix channel: [#fluent:mozilla.org](https://chat.mozilla.org/#/room/#fluent:mozilla.org)
33+
34+
## Get Involved
35+
36+
python-fluent is open-source, licensed under the Apache License, Version
37+
2.0. We encourage everyone to take a look at our code and we’ll listen
38+
to your feedback.

README.rst

Lines changed: 0 additions & 47 deletions
This file was deleted.

dev-requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

fluent.runtime/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# fluent.runtime
2+
3+
Use [Fluent](https://projectfluent.org/) to localize your Python application.
4+
It comes with a `Localization` class to use, based on an implementation of `FluentBundle`.
5+
It uses the parser from `fluent.syntax` to read Fluent files.
6+
7+
```python
8+
from datetime import date
9+
l10n = DemoLocalization("today-is = Today is { $today }")
10+
val = l10n.format_value("today-is", { "today": date.today() })
11+
val # 'Today is Jun 16, 2018'
12+
```
13+
14+
Find the full documentation at https://projectfluent.org/python-fluent/fluent.runtime/.

fluent.runtime/README.rst

Lines changed: 0 additions & 19 deletions
This file was deleted.

fluent.runtime/docs/usage.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,41 @@ instances to indicate an error or missing data. Otherwise they should
272272
return unicode strings, or instances of a ``FluentType`` subclass as
273273
above.
274274

275+
Attributes
276+
~~~~~~~~~~
277+
When rendering UI elements, it's handy to have a single translation that
278+
contains everything you need in one variable. For example, a HTML
279+
form input may have a value, but also a placeholder attribute, aria-label
280+
attribute, and maybe a title attribute.
281+
282+
.. code-block:: python
283+
284+
>>> l10n = DemoLocalization("""
285+
... login-input = Predefined value
286+
... .placeholder = { $email }
287+
... .aria-label = Login input value
288+
... .title = Type your login email
289+
... """)
290+
>>> value, attributes = l10n.format_message(
291+
... "login-input", {"email": "email@example.com"}
292+
... )
293+
>>> value
294+
'Predefined value'
295+
>>> attributes
296+
{'placeholder': 'email@example.com', 'aria-label': 'Login input value', 'title': 'Type your login email'}
297+
298+
You can also use the formatted message without unpacking it.
299+
300+
.. code-block:: python
301+
302+
>>> fmt_msg = l10n.format_message(
303+
... "login-input", {"email": "email@example.com"}
304+
... )
305+
>>> fmt_msg.value
306+
'Predefined value'
307+
>>> fmt_msg.attributes
308+
{'placeholder': 'email@example.com', 'aria-label': 'Login input value', 'title': 'Type your login email'}
309+
275310
Known limitations and bugs
276311
~~~~~~~~~~~~~~~~~~~~~~~~~~
277312

fluent.runtime/fluent/runtime/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from fluent.syntax.ast import Resource
33

44
from .bundle import FluentBundle
5-
from .fallback import AbstractResourceLoader, FluentLocalization, FluentResourceLoader
5+
from .fallback import AbstractResourceLoader, FluentLocalization, FluentResourceLoader, FormattedMessage
66

77
__all__ = [
88
"FluentLocalization",
99
"AbstractResourceLoader",
1010
"FluentResourceLoader",
1111
"FluentResource",
1212
"FluentBundle",
13+
"FormattedMessage",
1314
]
1415

1516

0 commit comments

Comments
 (0)