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

class ITranslator(ABC): (source)

Known subclasses: orionis.localization.Translator

View In Hierarchy

Define the contract for the translation service.

The translator resolves lines for the active locale, falls back to the configured fallback locale, applies parameter replacement, and selects pluralized segments.

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
@abstractmethod
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.
@abstractmethod
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.
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.
@abstractmethod
def flush(self): (source)

Discard every cached translation map.

Returns
NoneUndocumented
@abstractmethod
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.
@abstractmethod
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.
@abstractmethod
def getLocale(self) -> str: (source)

Return the active locale.

Returns
strLocale code currently in use.
@abstractmethod
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.
@abstractmethod
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
@abstractmethod
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.
@abstractmethod
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.
__slots__: tuple = (source)

Undocumented