ORIONIS API REFERENCE

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 documentation

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.

Notes

The provider binds a single instance for the whole process and the class uses no lock, so setLocale, missing, reload, forget and flush are global side effects visible to every concurrent task. Pass an explicit locale to get, has or choice to select a language for a single call instead.

Method __applyReplacements Substitute placeholders into a translation line.
Method __asNumber Parse a plural condition token into a number.
Method __assertLocale Validate a locale code and return it unchanged.
Method __init__ Initialize the translator with its locales and collaborators.
Method __matchesBound Evaluate one bound of an explicit range condition.
Method __matchExplicitSegment Select the plural segment whose explicit condition matches.
Method __matchPluralSegment Select the plural segment through positional rules.
Method __resolveMissing Resolve the line for a missing translation key.
Method __stripCondition Remove a leading explicit condition from a plural segment.
Method availableLocales 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 getLocale 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 setLocale 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
def __applyReplacements(self, line: str, replace: dict[str, object]) -> str: (source)

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:strTranslation line containing the placeholders.
replace:dict[str, object]Mapping of placeholder name to replacement value.
Returns
strLine with every placeholder substituted.
def __asNumber(self, raw: str) -> float | None: (source)

Parse a plural condition token into a number.

Parameters
raw:strCondition token extracted from a plural segment.
Returns
float | NoneNumeric value, or None when the token is not numeric.
def __assertLocale(self, locale: str) -> str: (source)

Validate a locale code and return it unchanged.

Parameters
locale:strLocale code to validate.
Returns
strThe validated locale code.
Raises
InvalidLocaleExceptionIf the locale is empty, malformed, or unsafe for path use.
def __init__(self, *, locale: str, fallback: str, loader: ITranslationLoader, repository: ITranslationRepository): (source)

Initialize the translator with its locales and collaborators.

Parameters
locale:strActive locale code.
fallback:strLocale used when a translation is missing.
loader:ITranslationLoaderLoader used to discover the available locales.
repository:ITranslationRepositoryIn-memory cache resolving translation maps per locale.
Returns
NoneUndocumented
Raises
InvalidLocaleExceptionIf either locale code is malformed.
def __matchesBound(self, raw: str, count: int, *, lower_bound: bool) -> bool: (source)

Evaluate one bound of an explicit range condition.

Parameters
raw:strBound token, either a number or the * wildcard.
count:intQuantity evaluated against the bound.
lower_bound:boolWhether the token is the lower bound of the range.
Returns
boolTrue when the count satisfies the bound.
def __matchExplicitSegment(self, segments: list[str], count: int) -> str | None: (source)

Select the plural segment whose explicit condition matches.

Parameters
segments:list[str]Plural segments split from the raw translation line.
count:intQuantity evaluated against each condition.
Returns
str | NoneMatching segment body, or None when no explicit condition applies.
def __matchPluralSegment(self, segments: list[str], count: int) -> str: (source)

Select the plural segment through positional rules.

Parameters
segments:list[str]Plural segments split from the raw translation line.
count:intQuantity used to pick singular or plural form.
Returns
strSelected segment stripped of any explicit condition.
def __resolveMissing(self, key: str, locale: str) -> str: (source)

Resolve the line for a missing translation key.

Parameters
key:strTranslation key that produced no match.
locale:strLocale in which the key was requested.
Returns
strReplacement line provided by the handler, or the key itself.
def __stripCondition(self, segment: str) -> str: (source)

Remove a leading explicit condition from a plural segment.

Parameters
segment:strRaw plural segment possibly prefixed by a condition.
Returns
strSegment body without its condition, trimmed of whitespace.
def availableLocales(self) -> tuple[str, ...]: (source)

Return every locale with at least one translation source.

Returns
tuple[str, ...]Sorted locale codes discovered in the language path.
def choice(self, key: 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:strTranslation key containing the pluralized segments.
count:intQuantity 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, optionalLocale to translate into, or None for the active locale.
**replace:objectPlaceholder values substituted into the selected segment.
Returns
strPluralized and interpolated translation line.
Raises
InvalidLocaleExceptionIf an explicit locale is malformed.
def flush(self): (source)

Discard every cached translation map.

Returns
NoneUndocumented
def forget(self, locale: str) -> bool: (source)

Discard the cached translations for a single locale.

Parameters
locale:strLocale code whose cache entry must be removed.
Returns
boolTrue when an entry was removed, False otherwise.
Raises
InvalidLocaleExceptionIf the locale is malformed.
def get(self, key: str, locale: str | None = None, **replace: object) -> str: (source)

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:strTranslation key, either a literal source text or a dot-notated grouped key such as validation.required.
locale:str | None, optionalLocale to translate into, or None for the active locale.
**replace:objectPlaceholder values substituted into the resolved line.
Returns
strTranslated line, or the key itself when missing.
Raises
InvalidLocaleExceptionIf an explicit locale is malformed.
def getLocale(self) -> str: (source)

Return the active locale.

Returns
strLocale code currently in use.
def has(self, key: str, locale: str | None = None, *, fallback: bool = True) -> bool: (source)

Determine whether a translation exists for key.

Parameters
key:strTranslation key to check.
locale:str | None, optionalLocale to inspect, or None for the active locale.
fallback:bool, optionalWhether the fallback locale is also inspected.
Returns
boolTrue when a translation line is registered for the key.
Raises
InvalidLocaleExceptionIf an explicit locale is malformed.
def missing(self, handler: MissingKeyHandler | None): (source)

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 | NoneCallable invoked on missing keys, or None to remove the current handler.
Returns
NoneUndocumented
def reload(self, locale: str | None = None): (source)

Discard cached translations so they are re-read from disk.

Parameters
locale:str | None, optionalLocale to reload, or None to reload every locale.
Returns
NoneUndocumented
Raises
InvalidLocaleExceptionIf an explicit locale is malformed.
def setLocale(self, locale: str): (source)

Change the active locale at runtime.

Parameters
locale:strLocale code to activate.
Returns
NoneUndocumented
Raises
InvalidLocaleExceptionIf the locale is malformed.
_fallback = (source)

Undocumented

Undocumented

Undocumented

_missing: MissingKeyHandler | None = (source)

Undocumented

_repository = (source)

Undocumented