PumpWood I8n
This package provides internationalization for Pumpwood systems. It can
translate sentences through a remote microservice backend or a local model
class that implements a translate method.
Pumpwood is a native Brazilian tree
which has a symbiotic relation with ants (Murabei)
Quick start
The main class in the package is PumpwoodI8n. It translates sentences
through the t method.
Remote backend (microservice)
from pumpwood_i8n.translate import PumpwoodI8n
from pumpwood_communication.microservices import PumpWoodMicroService
# Instantiate a microservice object to call the backend for translation.
microservice = PumpWoodMicroService(
server_url='http://localhost/',
username="pumpwood", password="is a nice system")
pumpwood_i8n = PumpwoodI8n(microservice=microservice)
translated_str = pumpwood_i8n.t(
sentence="Translate this sequence please?",
# Tags differentiate the same sentence in different contexts.
tag="login",
# Flag to indicate whether the translation is plural.
plural=False,
# Reference language for the translation.
language="",
# Optional user context for differentiated translations.
user_type="")
It is also possible to instantiate an empty object and configure it later.
from pumpwood_i8n.translate import PumpwoodI8n
from pumpwood_communication.microservices import PumpWoodMicroService
microservice = PumpWoodMicroService(
server_url='http://localhost/',
username="pumpwood", password="is a nice system")
pumpwood_i8n = PumpwoodI8n()
pumpwood_i8n.init(microservice=microservice)
Local backend (Django model)
When running inside a Django application, configure a local model instead of a microservice. Only one backend may be active at a time.
from pumpwood_i8n.translate import PumpwoodI8n
def django_apps_ready():
try:
from django.apps import apps
return apps.ready
except Exception:
return False
pumpwood_i8n = PumpwoodI8n(
i8n_model='pumpwood_djangoauth.i8n.models.PumpwoodI8nTranslation',
app_ready_check=django_apps_ready)
translated_str = pumpwood_i8n.t(
sentence="Translate this sequence please?", tag="login")
The model path can also be set through the PUMPWOOD_I8N__I8N_MODEL
environment variable. Pass app_ready_check when using a Django model
so translation is skipped until django.apps.apps.ready is True.
Singleton
Use the shared instance from singletons and initialize it at startup.
from pumpwood_i8n.singletons import pumpwood_i8n
from pumpwood_communication.microservices import PumpWoodMicroService
microservice = PumpWoodMicroService(
server_url='http://localhost/',
username="pumpwood", password="is a nice system")
pumpwood_i8n.init(microservice=microservice)
Cache
Pumpwood I8n can cache translations locally to avoid too many calls to
the backend. Cache entries expire after
PUMPWOOD_AUTH__I8N_CACHE_EXPIRATION seconds.
Environment parameters
PUMPWOOD_AUTH__I8N_CACHE_EXPIRATION [int]: Expiry time in seconds for
locally cached translations. After this period the sentence is translated
again and the local cache is renewed. Default is 300.
PUMPWOOD_I8N__I8N_MODEL [str]: Dotted path to the model class used for
local translation (lazy load). Example:
pumpwood_djangoauth.i8n.models.PumpwoodI8nTranslation.
Metadata
Release files for pumpwood-i8n 1.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pumpwood_i8n-1.0.6.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pumpwood_i8n-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.6 kB
Release files / pumpwood_i8n-1.0.6.tar.gz
| Download URL | pumpwood_i8n-1.0.6.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ddb7ff54f87814c28a869d84773576520ff01d4f6cddae260c469141056c1c9
|
|
BLAKE2b-256 checksum How to use checksums |
d5ae1cdb0f729c67620d8959c78e4ee9b2329586026bc9ddef5f002960a3f999
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure
|
Release files / pumpwood_i8n-1.0.6-py3-none-any.whl
| Download URL | pumpwood_i8n-1.0.6-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
381a156475b15a7e00a8e465ba3b0db1c56aa137162d91a3f0df50fdaa91ce25
|
|
BLAKE2b-256 checksum How to use checksums |
be391536b951c91cc06e17490d1ec37db329d279cb7c716eb52c21e190eee82e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.13 Linux/6.17.0-1020-azure
|