Skip to content

Commit 7adf018

Browse files
committed
Add API reference to README
1 parent c6cbbc3 commit 7adf018

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,60 @@ assert bundle.get_translation("hello-user", variables={"user": "Bob"}) == "Hello
4747
The Unicode characters around "Bob" in the above example are for
4848
[Unicode bidirectional handling](https://www.unicode.org/reports/tr9/).
4949

50+
## API reference
51+
52+
### `Bundle` class
53+
54+
A set of translations for a specific language.
55+
56+
```python
57+
import rustfluent
58+
59+
bundle = rustfluent.Bundle(
60+
language="en-US",
61+
ftl_files=[
62+
"/path/to/messages.ftl",
63+
"/path/to/more/messages.ftl",
64+
],
65+
)
66+
```
67+
68+
#### Parameters
69+
70+
| Name | Type | Description |
71+
|-------------|-------------|-------------------------------------------------------------------------------------------------------------------------|
72+
| `language` | `str` | [Unicode Language Identifier](https://unicode.org/reports/tr35/tr35.html#Unicode_language_identifier) for the language. |
73+
| `ftl_files` | `list[str]` | Full paths to the FTL files containing the translations. Entries in later files overwrite earlier ones. |
74+
75+
#### Raises
76+
77+
- `FileNotFoundError` if any of the FTL files could not be found.
78+
- `ValueError` if any of the FTL files contain errors.
79+
80+
### `Bundle.get_translation`
81+
82+
```
83+
>>> bundle.get_translation(identifier="hello-world")
84+
"Hello, world!"
85+
>>> bundle.get_translation(identifier="hello-user", variables={"user": "Bob"})
86+
"Hello, Bob!"
87+
```
88+
89+
#### Parameters
90+
91+
| Name | Type | Description |
92+
|--------------|-----------------------|------------------------------------------------------------------------------------------------------------|
93+
| `identifier` | `str` | The identifier for the Fluent message. |
94+
| `variables` | `list[str]`, optional | Any [variables](https://projectfluent.org/fluent/guide/variables.html) to be passed to the Fluent message. |
95+
96+
#### Return value
97+
98+
`str`: the translated message.
99+
100+
#### Raises
101+
102+
- `ValueError` if the message could not be found or has no translation available.
103+
50104
## Contributing
51105

52106
See [Contributing](./CONTRIBUTING.md).

0 commit comments

Comments
 (0)