Locale¶
_locale ¶
Locale normalization and fallback policy.
SUPPORTED_LOCALES
module-attribute
¶
SUPPORTED_LOCALES = frozenset({'en-GB', 'en-US', 'fr-FR', 'de-DE', 'zh-CN', 'zh-TW', 'ko-KR', 'pt-BR', 'es-ES', 'ja-JP', 'ru-RU', 'id-ID', 'vi-VN', 'th-TH', 'hi-IN', 'bn-IN', 'te-IN', 'mr-IN', 'ta-IN'})
LocaleResolution
dataclass
¶
resolve_locale ¶
Normalize a locale tag and return ordered lookup candidates.
The resolver intentionally covers the project's currently supported locale set instead of implementing full BCP 47 negotiation.
Source code in src/fortune_telling_core/_locale.py
normalize_locale ¶
Normalize a locale tag such as en_us to en-US.
A bare ISO 639 language code with no territory is accepted and mapped to its
default supported locale: for example fr -> fr-FR and ja -> ja-JP,
with en -> en-GB and zh -> zh-CN for the languages that have
more than one supported territory. A bare language with no supported territory
is returned lower-cased and simply resolves to no dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locale
|
str
|
Locale tag supplied by a request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonicalized locale tag. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the locale is empty or structurally unsupported. |