THE ORIONIS API
Build with clarity.
Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.
class Translator(ITranslator): (source)
Constructor: Translator(locale, fallback, loader, repository)
Resolve translation lines for the active locale.
The translator performs O(1) lookups against the in-memory
repository, falls back to the configured fallback locale, applies
style :name parameter replacement, and selects
pluralized segments through choice.
| Method | __apply |
Substitute placeholders into a translation line. |
| Method | __as |
Parse a plural condition token into a number. |
| Method | __assert |
Validate a locale code and return it unchanged. |
| Method | __init__ |
Initialize the translator with its locales and collaborators. |
| Method | __matches |
Evaluate one bound of an explicit range condition. |
| Method | __match |
Select the plural segment whose explicit condition matches. |
| Method | __match |
Select the plural segment through positional rules. |
| Method | __resolve |
Resolve the line for a missing translation key. |
| Method | __strip |
Remove a leading explicit condition from a plural segment. |
| Method | available |
Return every locale with at least one translation source. |
| Method | choice |
Retrieve a pluralized translation line based on count. |
| Method | flush |
Discard every cached translation map. |
| Method | forget |
Discard the cached translations for a single locale. |
| Method | get |
Retrieve the translation line registered under key. |
| Method | get |
Return the active locale. |
| Method | has |
Determine whether a translation exists for key. |
| Method | missing |
Register a handler invoked when a translation key is missing. |
| Method | reload |
Discard cached translations so they are re-read from disk. |
| Method | set |
Change the active locale at runtime. |
| Class Variable | __slots__ |
Undocumented |
| Instance Variable | _fallback |
Undocumented |
| Instance Variable | _loader |
Undocumented |
| Instance Variable | _locale |
Undocumented |
| Instance Variable | _missing |
Undocumented |
| Instance Variable | _repository |
Undocumented |
Substitute placeholders into a translation line.
Each parameter replaces its :key, :Key, and :KEY variants with the raw, capitalized, and uppercased value respectively. Longer parameter names are applied first so they are never shadowed by shorter prefixes.
| Parameters | |
line:str | Translation line containing the placeholders. |
replace:dict[str, object] | Mapping of placeholder name to replacement value. |
| Returns | |
str | Line with every placeholder substituted. |
Parse a plural condition token into a number.
| Parameters | |
raw:str | Condition token extracted from a plural segment. |
| Returns | |
float | None | Numeric value, or None when the token is not numeric. |
Validate a locale code and return it unchanged.
| Parameters | |
locale:str | Locale code to validate. |
| Returns | |
str | The validated locale code. |
| Raises | |
InvalidLocaleException | If the locale is empty, malformed, or unsafe for path use. |
str, fallback: str, loader: ITranslationLoader, repository: ITranslationRepository):
(source)
¶
Initialize the translator with its locales and collaborators.
| Parameters | |
locale:str | Active locale code. |
fallback:str | Locale used when a translation is missing. |
loader:ITranslationLoader | Loader used to discover the available locales. |
repository:ITranslationRepository | In-memory cache resolving translation maps per locale. |
| Returns | |
None | Undocumented |
| Raises | |
InvalidLocaleException | If either locale code is malformed. |
str, count: int, locale: str | None = None, **replace: object) -> str:
(source)
¶
Retrieve a pluralized translation line based on count.
Segments are separated by | and may declare explicit conditions such as {0}, {1} or ranges [2,*]. When no explicit condition matches, the first segment is used for a count of one and the second segment otherwise. The :count placeholder is always available in the selected segment.
| Parameters | |
key:str | Translation key containing the pluralized segments. |
count:int | Quantity used to select the proper segment. The value is used as received: explicit conditions compare it against their numeric bounds and the positional rule tests count == 1. No coercion or validation is applied, so a non-numeric quantity propagates the comparison TypeError raised by Python. |
locale:str | None, optional | Locale to translate into, or None for the active locale. |
**replace:object | Placeholder values substituted into the selected segment. |
| Returns | |
str | Pluralized and interpolated translation line. |
| Raises | |
InvalidLocaleException | If an explicit locale is malformed. |
Discard the cached translations for a single locale.
| Parameters | |
locale:str | Locale code whose cache entry must be removed. |
| Returns | |
bool | True when an entry was removed, False otherwise. |
| Raises | |
InvalidLocaleException | If the locale is malformed. |
Retrieve the translation line registered under key.
The lookup order is the requested locale first, then the fallback locale, and finally the key itself when no translation exists. Placeholders in the :name form are substituted with the values provided in replace.
| Parameters | |
key:str | Translation key, either a literal source text or a dot-notated grouped key such as validation.required. |
locale:str | None, optional | Locale to translate into, or None for the active locale. |
**replace:object | Placeholder values substituted into the resolved line. |
| Returns | |
str | Translated line, or the key itself when missing. |
| Raises | |
InvalidLocaleException | If an explicit locale is malformed. |
Determine whether a translation exists for key.
| Parameters | |
key:str | Translation key to check. |
locale:str | None, optional | Locale to inspect, or None for the active locale. |
fallback:bool, optional | Whether the fallback locale is also inspected. |
| Returns | |
bool | True when a translation line is registered for the key. |
| Raises | |
InvalidLocaleException | If an explicit locale is malformed. |
Register a handler invoked when a translation key is missing.
The handler receives the key and the locale, and may return a replacement line. When it returns None the key itself is used as the translation.
| Parameters | |
handler:MissingKeyHandler | None | Callable invoked on missing keys, or None to remove the current handler. |
| Returns | |
None | Undocumented |
Discard cached translations so they are re-read from disk.
| Parameters | |
locale:str | None, optional | Locale to reload, or None to reload every locale. |
| Returns | |
None | Undocumented |
| Raises | |
InvalidLocaleException | If an explicit locale is malformed. |
Change the active locale at runtime.
| Parameters | |
locale:str | Locale code to activate. |
| Returns | |
None | Undocumented |
| Raises | |
InvalidLocaleException | If the locale is malformed. |