i21y.loaders package¶
Submodules¶
i21y.loaders.file_ module¶
- class i21y.loaders.file_.LocaleFile(parent: Loader, locale: str, path: PurePath)¶
Bases:
objectClass 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:
LoaderLoader 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.Loaderprovided 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_.LocaleFilewith 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.PurePathrepresenting 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[Undefined] | 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:
LoaderLoader implemented to load json files. By default, json is read using the standard module json. But if you have
orjsonori21y[fast-json]installed, json reading is done with the library called orjson. The arguments of constructor are same asfile_.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_.LocaleFilewith 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:
LoaderLoader implemented to load YAML files. To use it, you must have
pyyamlori21y[yaml]installed. The arguments of constructor are same asfile_.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_.LocaleFilewith empty data.- Parameters:
path – The path to the file.