No project description provided
Project description
rustfluent
A Python interface to the Rust Fluent Library.
This project is a small shim around fluent-rs, so it can be used from Python.
[!WARNING] This package is under active development, and breaking changes may be released at any time. Be sure to pin to specific versions if you're using this package in a production environment.
Prerequisites
This package supports:
- Python 3.11
- Python 3.12
Installation
pip install rustfluent
Usage
import rustfluent
# First load a bundle
bundle = rustfluent.Bundle(
"en",
[
# Multiple FTL files can be specified. Entries in later
# files overwrite earlier ones.
"en.ftl",
],
)
# Fetch a translation
assert bundle.get_translation("hello-world") == "Hello World"
# Fetch a translation that includes variables
assert bundle.get_translation("hello-user", variables={"user": "Bob"}) == "Hello, \u2068Bob\u2069"
The Unicode characters around "Bob" in the above example are for Unicode bidirectional handling.
API reference
Bundle
class
A set of translations for a specific language.
import rustfluent
bundle = rustfluent.Bundle(
language="en-US",
ftl_files=[
"/path/to/messages.ftl",
"/path/to/more/messages.ftl",
],
)
Parameters
Name | Type | Description |
---|---|---|
language |
str |
Unicode Language Identifier for the language. |
ftl_files |
list[str] |
Full paths to the FTL files containing the translations. Entries in later files overwrite earlier ones. |
strict |
bool , optional |
In strict mode, a ParserError will be raised if there are any errors in the file. In non-strict mode, invalid Fluent messages will be excluded from the Bundle. |
Raises
FileNotFoundError
if any of the FTL files could not be found.rustfluent.ParserError
if any of the FTL files contain errors (strict mode only).
Bundle.get_translation
>>> bundle.get_translation(identifier="hello-world")
"Hello, world!"
>>> bundle.get_translation(identifier="hello-user", variables={"user": "Bob"})
"Hello, \u2068Bob\u2069!"
>>> bundle.get_translation(identifier="hello-user", variables={"user": "Bob"}, use_isolating=False)
"Hello, Bob!"
Parameters
Name | Type | Description |
---|---|---|
identifier |
str |
The identifier for the Fluent message. |
variables |
`dict[str, str | int ]`, optional |
use_isolating |
bool , optional |
Whether to insert Unicode Directionality Isolation Marks around placeables, to indicate that their direction may differ from the surrounding message. Defaults to True . |
Return value
str
: the translated message.
If there is a problem with a passed variable (e.g. it is of the wrong type or an integer that is larger than a signed long integer), then the name of the variable will be used instead.
Raises
ValueError
if the message could not be found or has no translation available.TypeError
if a passed variable name (i.e. a key in thevariables
dict) is not a string.
Contributing
See Contributing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for rustfluent-0.1.0a5-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2cb8b2bf0537c888c377ccbe44dbc06f8d2d059d1d857c4c033f2f59a4ce88b |
|
MD5 | 1060a40286bce265f5dadf80a226cf62 |
|
BLAKE2b-256 | 0ca31553b424ac02187fd6608dbf9da34d907634e365a540df20c7c4891015ff |
Hashes for rustfluent-0.1.0a5-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59980f2306ca01719ec920412cae93bfd7b26dcbf156b90efeb0d469f13f396c |
|
MD5 | 02e6f9bc16a12219474cbb3e4b0cd59f |
|
BLAKE2b-256 | 68c140ec6dd4756b0fb87605b38aaa4c1217fb141b841cbd3fe2fa27831acdd6 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 323308295b96bb002862c18800bc9a14c6037637fa14d2ad72e4bd6a80573dc4 |
|
MD5 | 0bf453a1e25de4cfb78a577cedeff0f5 |
|
BLAKE2b-256 | c9ad4f7ebb271d45a6d78cc1a0ca1bbdac5576202c48c9624ade8d5695aec346 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-musllinux_1_2_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe970add658ff845a7e4c7d710f65c61069fdb32e4b14c5abc2dcc868f9484f |
|
MD5 | 37809d926fe18d886ef88d42d961615a |
|
BLAKE2b-256 | 31afe3a49390a8484d1a96281aebf25e4076511456d9f9962fbcbbf1398d5a44 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd736aed51a586632810ed715fca12ace6c3630dd1abee7a6b1d4b432bc6c5f1 |
|
MD5 | 4f2bec6f06841f175b993a1f28cd44bd |
|
BLAKE2b-256 | 506a110285f44a54416b2cc1b60e4ad0fd69aba260d66223d7e8d484a1419c32 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b5625b4d83156702d3d08d60b8e099f8414773d562a22888cc5a3acd60665e |
|
MD5 | 856be60a0a5c206c3ab4f32eceba67b4 |
|
BLAKE2b-256 | e1fc558fc312f838bea526d05208043bdb364f247247ad3948f0155df07df968 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b9a13626de73ebdf8e8705f49d315551c2ab63f3aa85d72979315f44e3fcbf6 |
|
MD5 | 9cd4b845e4d2741c3a539d0979c4c15d |
|
BLAKE2b-256 | f2f4ef079d5a86815891ee46da2290cef2f3bfcd887d8b7f2e4cf43341e35f5d |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40f3969403f8c18558ba293f30ff2cc3b844c7391c24ecf48ea0ac00c299f7f |
|
MD5 | fabf0d749aa97034217ada81660f5e3d |
|
BLAKE2b-256 | 0a0c762989c491d89e1dd78c949476e57281597563361234931f2ffd581480cd |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccfc015285af88275e35edcd364a6a3c82fa1cb35025cd63a5d916493b734255 |
|
MD5 | 7d4923053c05b1bc7bf729d04f1e5d6c |
|
BLAKE2b-256 | eff5400472bbde38b918c812522c9c83bb758fc29e6b65f989f31e5d120a312b |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f9261a690626ca7fea12705e570ddc89b97f2c46307a16cb0a2927a54b64dd5 |
|
MD5 | 090dca45462361e9478fbd68955c1dd4 |
|
BLAKE2b-256 | e70ef1d1633afb38527784205acc273d4325518b72409ec240d039c9a761ab24 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6befab8d4aa725322bd4ab604cb35dc4f458847b777e8a73c25902c03570bca8 |
|
MD5 | a97668287531cc57a5fff6e6959d78b5 |
|
BLAKE2b-256 | 7e9729a287bafe990b8c44c99bdc2388d407dd9b51224fea83f7f20e0e1f3e3b |
Hashes for rustfluent-0.1.0a5-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a81cd11dbbfde2a68f37ab0ed54cb0d79dd2c0c3cd853edcbaff13c5a3bcacd |
|
MD5 | b6a611e4a2cb7e529dcf723e5071a041 |
|
BLAKE2b-256 | db74f9720b170d01b487aee3bf9f1ff40982b82e22d4570cb8b36b6480ddddde |
Hashes for rustfluent-0.1.0a5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f0f965b135f99c2cc7dd6bdfee2e40880570ac74f5fb69acdd92323b04a9d8e |
|
MD5 | 624daf8b36e64da78b25cb2e4ec6a2e5 |
|
BLAKE2b-256 | 26a857d64e36fe90fd89f9db3152e9050f2f8ad27aca7d0758a20010527ae024 |
Hashes for rustfluent-0.1.0a5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a281b13c0cbdd4a2e86128e48b361d332a25a34930801ab7e0ac267486779a |
|
MD5 | 7984f68e5d509f3a5a5a9274dbf0a201 |
|
BLAKE2b-256 | d47b2644d4842af3d082dc7b804768855838a20764351b2d68476124f277ec99 |
Hashes for rustfluent-0.1.0a5-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f969e1ca7e97c3a071fe1be075f4cbc15be5c526e9206d28dfb53e53c7cddac |
|
MD5 | 62e69daa9db77a3df0403487df25542d |
|
BLAKE2b-256 | 323e15acd6a090d1fc9e968c46cf2a6869cd08b4a9a06e858a16e0dfe6ecb9fa |
Hashes for rustfluent-0.1.0a5-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8831bde9ed728eaa4cd88a96d172d9483e7616b52d1c0e952c4cfff983d624c |
|
MD5 | c0f4b30c46aaa9d7934e92af18a551f0 |
|
BLAKE2b-256 | 62cbf1f77c28f6f8391da0db4aa2123dcf11bb0287c473cc54aaa0c3f2029e77 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172f5857300278efe983e3cf7d98d8a4d5f370b254e002b7afed66509fcf2f23 |
|
MD5 | 5a2136e38e8e80b7b81f425575d2daaf |
|
BLAKE2b-256 | 89dec2d978c8b5c514324851203b229e1646d0e542b0f7742d49658ffac21652 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-musllinux_1_2_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2314138593b090b88c5fb584b699cd70a4838b76a2f5b7096f14395dc7ede7be |
|
MD5 | 7b5a6f6514f25d8ab37ebbf4d2e5a9a5 |
|
BLAKE2b-256 | 0b860d671b01711b27eb01a73b9a2947c50ffb257521a42b525a29a081c9955e |
Hashes for rustfluent-0.1.0a5-cp311-cp311-musllinux_1_2_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ec3a8d12b45fd0745899eea5d173d4a0484791f4ec88b41caf15582a0b4093c |
|
MD5 | 2da15df055fca86cbff4e7d9778738d3 |
|
BLAKE2b-256 | 20eda5f0587c6f512959b51c0081fcc795366e47944a20c2564817c3aaf33233 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4abc70c44433251f82c98aa26939618ee0c8c8df1079526f382953bf306592ce |
|
MD5 | bb431b4469668061a9b056fe2104ee75 |
|
BLAKE2b-256 | 5d79ee664b71a91e1f03565474e5e79d92b1d08f09db3e13497acf43ac2afdfc |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc1be8bc6e9f5be1046d2d57da2f454caa68bf140fe03e5f7564379334db4672 |
|
MD5 | 8b116b1b1d41e47fecd8f22fb0b5f2d5 |
|
BLAKE2b-256 | ba3e9558dab3b7285f05e2220121f74d3cfc6a8fd4dd634bfe58a4f67958f0cb |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bf4f119bac3cf15744ba84d033a65eda8dc7d6885eb804c1fafe00d9522d825 |
|
MD5 | 985f1cf54d8b407fc5e01849272a8346 |
|
BLAKE2b-256 | 64e06428291c102faf5ee7958be984f14f5b1f83a5bf98c02b9f65c3278a4440 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df93ae71f8d8519766c8b9f7faa8a85f306ec85ef6ee802f503bdae7c0a4f075 |
|
MD5 | d6b0dbd3868373f08b22f8bf268983b7 |
|
BLAKE2b-256 | ec9127a7583120f9823d5855dcd37ee0367b62bb0e791beac5cd87b7cf7f9208 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dfbdeb7fafd6746b9b318d981bfe12802c7189749b5c8d47a2f1d67a6d2ac11 |
|
MD5 | 36854cd766924a1731fe995c2d3b73f9 |
|
BLAKE2b-256 | 87ca301387df309fbad65e7156effd82da8f7ee38d42b2ae884461815250e6fe |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c61ecbfb471ea43ba3acca7f508362f6c054b37bbbf0736f1b1d7aea8cffa24 |
|
MD5 | fc5b051f378da9dd26b9c5388cb1800e |
|
BLAKE2b-256 | ff8762806fe29b96138650f9eafcd6806e3b59d817cbda987fb70949b58e02bf |
Hashes for rustfluent-0.1.0a5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d79660e1fa94882f7ed44ed0dc8659c43c603d38fb552986af7fd353563ffea5 |
|
MD5 | 9d182846d6c7bb5dcc110b43d9977dad |
|
BLAKE2b-256 | 37c227b20ff14cc83cf7d17dc999c22f62e17ace08854ed92572612df3bf9792 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ee2c7d35100975567efc67bc2411b5c145a4c377cdcab0fd1ef7416c0a977b8 |
|
MD5 | a9b5561aae06694b317cf201aa54ef9e |
|
BLAKE2b-256 | 649a3ed14233a5ebe7e58ca4beb56815680e0c854de1712cd4e8b85581851e19 |
Hashes for rustfluent-0.1.0a5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e08df2ca59fde3fb3c32b08ada449a9773d450edf860465a34c7e8d890c5f7d |
|
MD5 | 277f0c1160af392094d0380444d6b2de |
|
BLAKE2b-256 | 48468b01b7de9d1d1c5f5f76c17da0015a67fd35c40d054efbfbe47111b6b173 |