i21y.loaders package

Submodules

i21y.loaders.file_ module

class i21y.loaders.file_.LocaleFile(parent: Loader, locale: str, path: PurePath)

Bases: object

Class for handling translation data file.

Parameters:
  • parent – The source from which the instance was created.

  • locale – The locale of the file.

  • path – The path to the file.

get(key: str | Iterable[str]) str | None

Search for translations in this file.

Parameters:

key – The key to search for translations.

class i21y.loaders.file_.Loader(path: str | PurePath, preload_cache: bool = True, use_cache_realtime: bool = True, do_not_search_file: bool = False)

Bases: Loader

Loader class implemented for loading files. This is just an environment for loading files, and is not implemented to actually load json files, etc. So, if you want to use it in real life, you can either implement it yourself, or use the json.Loader provided by i21y.

Parameters:
  • path – Path to directory for placeing translations. It is often set to locale.

  • preload_cache – Whether to run make_cache() when initializing the instance.

  • use_cache_realtime – Whether to search and collect caches when translating.

  • do_not_search_file – Whether to prevent file searches from being performed. If you do not want IO processing during translation, you can set this to True.

EXTENSIONS = ()

A tuple of supported file extensions. This must not be empty.

load(path: PurePath) LocaleFile

Load the file. You must implement it to load the data from the file. The default implementation returns an instance of file_.LocaleFile with empty data.

Parameters:

path – The path to the file.

make_cache() None

Searches for translations and generates a cache.

get_locale_path(locale: str) PurePath

Create an instance of pathlib.PurePath representing the path to the folder where the translations are located.

Parameters:

locale – The locale of translations.

search_locale_file(locale: str, key: str) tuple[list[str], LocaleFile] | None

Searchs for translations file.

Parameters:
  • locale – The locale of translations.

  • key – The key to translations.

search_impl(locale: str, key: str, default: type[~i21y.utils.Undefined] | ~i21y.abc.SearchT = <class 'i21y.utils.Undefined'>) str | SearchT

Implementation of abc.Loader.search(). Arguments is same as .search.

i21y.loaders.json module

class i21y.loaders.json.Loader(path: str | PurePath, preload_cache: bool = True, use_cache_realtime: bool = True, do_not_search_file: bool = False)

Bases: Loader

Loader implemented to load json files. By default, json is read using the standard module json. But if you have orjson or i21y[fast-json] installed, json reading is done with the library called orjson. The arguments of constructor are same as file_.Loader.

EXTENSIONS = ('.json',)

A tuple of supported file extensions. This must not be empty.

load(path: PurePath) LocaleFile

Load the file. You must implement it to load the data from the file. The default implementation returns an instance of file_.LocaleFile with empty data.

Parameters:

path – The path to the file.

i21y.loaders.yaml module

class i21y.loaders.yaml.Loader(path: str | PurePath, preload_cache: bool = True, use_cache_realtime: bool = True, do_not_search_file: bool = False)

Bases: Loader

Loader implemented to load YAML files. To use it, you must have pyyaml or i21y[yaml] installed. The arguments of constructor are same as file_.Loader.

EXTENSIONS = ('.yml', '.yaml')

A tuple of supported file extensions. This must not be empty.

load(path: PurePath) LocaleFile

Load the file. You must implement it to load the data from the file. The default implementation returns an instance of file_.LocaleFile with empty data.

Parameters:

path – The path to the file.

Module contents