Skip to content

Translation

other_lang_to_odia

other_lang_to_odia(
    text: str, source_language_code: str = "en"
) -> str

Translate from English to Odia language

odia_to_other_lang

odia_to_other_lang(
    text: str, dest_language_code: str = "en"
) -> str

Translate from Odia to other language

universal_translation

universal_translation(
    text: str,
    source_language_code: str = "en",
    dest_language_code: str = "or",
) -> str

Translate from any language to any By default it works for English to Odia. Based on the source and destination language provided, it can work for any languages supported.

cache

Translation cache configuration and observability.

The package keeps an in-memory LRU of translation results. By default it holds 10,000 entries and is hidden from callers.

Use the helpers in this module to:

  • enlarge / shrink the LRU,
  • enable a persistent disk cache (requires the [cache] extra),
  • observe hit/miss counts,
  • clear the cache.

Configuration may also be set via environment variables at import time:

  • OPENODIA_CACHE_MAX_SIZE — integer LRU size (default 10000).
  • OPENODIA_CACHE_DISK — path to a directory used for disk persistence.
Example

from openodia import cache cache.configure(max_size=50_000) cache.stats()

CacheStats

Bases: TypedDict

Snapshot of cache counters.

TranslationCache

LRU cache for translation results, with optional disk persistence.

Keys are arbitrary hashable tuples; the package uses (text, source_lang, dest_lang) triples. Values are translated strings.

Parameters:

Name Type Description Default
max_size int

Maximum number of entries to keep in memory. Must be ≥ 1.

DEFAULT_MAX_SIZE
disk_path Path | str | None

Optional directory for persistent storage. Requires diskcache (install with pip install openodia[cache]).

None

max_size property

max_size: int

Configured LRU capacity.

disk_enabled property

disk_enabled: bool

Whether disk persistence is currently active.

get

get(key: Any) -> str | None

Return a cached value or None if missing.

Hits in memory are moved to the most-recently-used position. Hits on disk are promoted to memory.

set

set(key: Any, value: str) -> None

Insert into memory (and disk, if configured).

stats

stats() -> CacheStats

Return current hit/miss/size counters.

clear

clear() -> None

Drop all entries (memory + disk) and reset counters.

clear

clear() -> None

Drop all entries and reset counters in the active cache.

configure

configure(
    max_size: int | None = None,
    disk_path: Path | str | None = None,
) -> TranslationCache

Replace the active cache with a new configuration.

Parameters:

Name Type Description Default
max_size int | None

New LRU capacity. None keeps the current value.

None
disk_path Path | str | None

Path for disk persistence; None disables disk persistence. To keep the existing disk path, pass it again.

None

Returns:

Type Description
TranslationCache

The newly-installed cache instance.

get_cache

get_cache() -> TranslationCache

Return the active cache instance, building it lazily on first use.

stats

stats() -> CacheStats

Snapshot of the active cache's counters.