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 (default10000).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
|
None
|
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.
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
|
disk_path
|
Path | str | None
|
Path for disk persistence; |
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.