Skip to content

Languages

Language

Language(language_filepath)

The class reflects the file with the translation.

Parameters
Parameter Default Description
language_filepath
str
required

The path to the file with the translation.

Raises
Type Description
FileNotFoundError

It is called if the file with the translation does not exist.

author property

author

The author of the translation taken from the translation file.

Returns
Type Description
str

The author's nickname.

author_url property

author_url

The link to the author of the translation is taken from the translation file.

Returns
Type Description
Optional[str]

Link to the author.

loaded property

loaded

If True, then the file with the translation is fully loaded in memory.

Returns
Type Description
bool

If loaded, then True.

mark property

mark

The name of the file without an extension.

Returns
Type Description
str

The name of the file without the extension.

name property

name

The path to the file with the translation.

Returns
Type Description
str

The full path to the file.

title property

title

The name of the translation language taken from the file.

Returns
Type Description
str

The purpose of the language.

words property

words

Special values that you need to have even if the language is not loaded.

Returns
Type Description
Dict[str, str]

Dictionary of special meanings.

get

get(key, default=None)

Getting a line feed.

Parameters
Parameter Default Description
key
str
required

The key to the variable with the translation, which is registered in the file with the translation.

default
Optional[str]
None

The default value. Defaults to None.

Raises
Type Description
LanguageNotLoadedError

It is called if the translation file is not fully loaded into memory.

Returns
Type Description
Optional[str]

Optional[str]: The translated string.

load

load()

Full load of the file with the translation in memory.

unload

unload()

Unload a file with a translation from memory.

LanguageLoader

LanguageLoader(
    langs_dirpath,
    main_lang_mark,
    default_lang_mark="en-eng",
)

The loader of files with translation.

Parameters
Parameter Default Description
langs_dirpath
str
required

The path to the folder with the translation files.

main_lang_mark
str
required

The name of the file with the main translation without the extension.

default_lang_mark
str
'en-eng'

The name of the file with the default translation without an extension. Defaults to "en-eng".

Raises
Type Description
FileNotFoundError

Called if the file with the default translation without the extension could not be found.

alangs property

alangs

Additional languages, for example, translation of plugins.

Returns
Type Description

A list with an additional translation.

default_lang property

default_lang

An image of the Language class reflecting the uploaded file with the default translation.

Returns
Type Description
Language

The translation.

default_lang_mark property

default_lang_mark

The name of the file with the default translation without an extension.

Returns
Type Description
str

The file name without an extension.

langs property

langs

A list with images of the Language class, reflecting the files found in the folder with the translation files.

Returns
Type Description
List[Language]

A list with translations.

main_lang property

main_lang

An image of the Language class reflecting the uploaded file with the main translation.

Returns
Type Description
Optional[Language]

The translation or None.

main_lang_mark property

main_lang_mark

The name of the file with the main translation without the extension.

Returns
Type Description
str

The file name without an extension.

name property

name

The path to the folder with the translation files.

Returns
Type Description
str

The full path to the file.

get

get(key)

First, it tries to get the translation from the file with the main translation, if it failed, it tries to get it from the file with the default translation, if it failed again, it tries to get them from additional languages (self.alangs). If in the end None is still output, then returns the string "<LTNF>", that is, the Language Text Not Found.

Parameters
Parameter Default Description
key
str
required

The key to the variable with the translation, which is registered in the file with the translation.

Returns
Name Type Description
str str

The translated string.

merge

merge(ll)

Adding additional languages (self.alangs).

Parameters
Parameter Default Description
ll
LanguageLoader
required

The image of the LanguageLoader class.