MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / load

Method load

src/pendulum/locales/locale.py:25–48  ·  view source on GitHub ↗
(cls, locale: str | Locale)

Source from the content-addressed store, hash-verified

23
24 @classmethod
25 def load(cls, locale: str | Locale) -> Locale:
26 from importlib import import_module, resources
27
28 if isinstance(locale, Locale):
29 return locale
30
31 locale = cls.normalize_locale(locale)
32 if locale in cls._cache:
33 return cls._cache[locale]
34
35 # Checking locale existence
36 actual_locale = locale
37 locale_path = cast(Path, resources.files(__package__).joinpath(actual_locale))
38 while not locale_path.exists():
39 if actual_locale == locale:
40 raise ValueError(f"Locale [{locale}] does not exist.")
41
42 actual_locale = actual_locale.split("_")[0]
43
44 m = import_module(f"pendulum.locales.{actual_locale}.locale")
45
46 cls._cache[locale] = cls(locale, m.locale)
47
48 return cls._cache[locale]
49
50 @classmethod
51 def normalize_locale(cls, locale: str) -> str:

Callers 6

localeFunction · 0.80
in_wordsMethod · 0.80
__init__Method · 0.80
formatMethod · 0.80
formatMethod · 0.80
parseMethod · 0.80

Calls 1

normalize_localeMethod · 0.80

Tested by

no test coverage detected