Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/pendulum/locales/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Locale:

_cache: ClassVar[dict[str, Locale]] = {}

# Mapping of deprecated/incorrect locale codes to their correct
# replacement, kept for backwards compatibility.
_ALIASES: ClassVar[dict[str, str]] = {
"ua": "uk", # Ukrainian: "ua" is an ISO 3166 country code (Ukraine),
# not the correct ISO 639 language code, which is "uk".
}

def __init__(self, locale: str, data: Any) -> None:
self._locale: str = locale
self._data: Any = data
Expand All @@ -33,7 +40,7 @@ def load(cls, locale: str | Locale) -> Locale:
return cls._cache[locale]

# Checking locale existence
actual_locale = locale
actual_locale = cls._ALIASES.get(locale, locale)
locale_path = cast(Path, resources.files(__package__).joinpath(actual_locale))
while not locale_path.exists():
if actual_locale == locale:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"""
ua custom locale file.
"""
from __future__ import annotations
translations = {
"units": {"few_second": "кілька секунд"},
# Relative time
"ago": "{} тому",
"from_now": "за {}",
"after": "{0} посіля",
"before": "{0} до",
# Date formats
"date_formats": {
"LTS": "HH:mm:ss",
"LT": "HH:mm",
"L": "DD.MM.YYYY",
"LL": "D MMMM YYYY р.",
"LLL": "D MMMM YYYY р., HH:mm",
"LLLL": "dddd, D MMMM YYYY р., HH:mm",
},
}
"""
uk custom locale file.
"""
from __future__ import annotations


translations = {
"units": {"few_second": "кілька секунд"},
# Relative time
"ago": "{} тому",
"from_now": "за {}",
"after": "{0} посіля",
"before": "{0} до",
# Date formats
"date_formats": {
"LTS": "HH:mm:ss",
"LT": "HH:mm",
"L": "DD.MM.YYYY",
"LL": "D MMMM YYYY р.",
"LLL": "D MMMM YYYY р., HH:mm",
"LLLL": "dddd, D MMMM YYYY р., HH:mm",
},
}
Loading