korone.utils package

Submodules

class korone.utils.i18n.LocaleStats(translated, untranslated, fuzzy, percent_translated)[source]

Bases: object

Represent the statistics of a locale.

This class represents the statistics of a locale, such as the number of translated strings, untranslated strings, fuzzy strings, and the percentage of translated strings.

translated

The number of translated strings.

Type:

int

untranslated

The number of untranslated strings.

Type:

int

fuzzy

The number of fuzzy strings.

Type:

int

percent_translated

The percentage of translated strings.

Type:

int

class korone.utils.i18n.I18nNew(*args, **kwargs)[source]

Bases: I18n

I18n class with additional functionality.

This class extends the I18n class and provides additional functionality for handling internationalization.

Parameters:
  • *args (Any) – Positional arguments to be passed to the I18n class.

  • **kwargs (Any) – Keyword arguments to be passed to the I18n class.

babels
stats
parse_stats(locale_code)[source]

Parse the statistics of a specific locale.

Parses the statistics of a specific locale, such as the number of translated strings,

Parameters:

locale_code (str) – The code of the locale.

Returns:

LocaleStats | None – An instance of the LocaleStats class representing the statistics of the locale, or None if the locale file does not exist.

babel(locale_code)[source]

Retrieve the Locale instance for a specific locale code.

This method retrieves the Locale instance for a specific locale code.

Parameters:

locale_code (str) – The code of the locale.

Returns:

Locale – An instance of the Locale class representing the locale.

property current_locale_babel

Retrieve the Locale instance for the current locale.

This property retrieves the Locale instance for the current locale.

Returns:

Locale – An instance of the Locale class representing the current locale.

locale_display(locale)[source]

Return the display name of a specific locale.

This method returns the display name of a specific locale.

Parameters:

locale (Locale) – An instance of the Locale class representing the locale.

Returns:

str – The display name of the locale.

property current_locale_display

Return the display name of the current locale.

This property returns the display name of the current locale.

Returns:

str – The display name of the current locale.

get_locale_stats(locale_code)[source]

Retrieve the statistics of a specific locale.

This method retrieves the statistics of a specific locale, such as the number of translated strings, untranslated strings, fuzzy strings, and the percentage of translated strings.

Parameters:

locale_code (str) – The code of the locale.

Returns:

LocaleStats | None – An instance of the LocaleStats class representing the statistics of the locale, or None if the statistics cannot be parsed.

get_current_locale_stats()[source]

Retrieve the statistics of the current locale.

This method retrieves the statistics of the current locale, such as the number of translated strings, untranslated strings, fuzzy strings, and the percentage of translated strings.

Returns:

LocaleStats | None – An instance of the LocaleStats class representing the statistics of the current locale, or None if the statistics cannot be parsed.

is_current_locale_default()[source]

Check if the current locale is the default locale.

This method checks if the current locale is the default locale.

Returns:

bool – True if the current locale is the default locale, False otherwise.

korone.utils.i18n.get_i18n()[source]

Get the current I18n context.

This function returns the current I18n context.

Returns:

I18n – The current I18n context.

Raises:

LookupError – If the I18n context is not set.

korone.utils.i18n.gettext(*args, **kwargs)[source]

Get the translated string for the given message.

This function returns the translated string for the given message.

Parameters:
  • *args (Any) – Positional arguments for the message.

  • **kwargs (Any) – Keyword arguments for the message.

Returns:

str – The translated string.

korone.utils.i18n.lazy_gettext(*args, **kwargs)[source]

Return a lazy proxy object for translating text.

This can be used, for example, to implement lazy translation functions that delay the actual translation until the string is actually used. The rationale for such behavior is that the locale of the user may not always be available. In web applications, you only know the locale when processing a request.

Parameters:
  • *args (Any) – Positional arguments to be passed to the gettext function.

  • **kwargs (Any) – Keyword arguments to be passed to the gettext function.

Returns:

LazyProxy – A lazy proxy object that represents the translated text.

korone.utils.i18n.ngettext(*args, **kwargs)

Get the translated string for the given message.

This function returns the translated string for the given message.

Parameters:
  • *args (Any) – Positional arguments for the message.

  • **kwargs (Any) – Keyword arguments for the message.

Returns:

str – The translated string.

korone.utils.i18n.lazy_ngettext(*args, **kwargs)

Return a lazy proxy object for translating text.

This can be used, for example, to implement lazy translation functions that delay the actual translation until the string is actually used. The rationale for such behavior is that the locale of the user may not always be available. In web applications, you only know the locale when processing a request.

Parameters:
  • *args (Any) – Positional arguments to be passed to the gettext function.

  • **kwargs (Any) – Keyword arguments to be passed to the gettext function.

Returns:

LazyProxy – A lazy proxy object that represents the translated text.

Perform a breadth-first search (BFS) for an attribute in an object.

The function performs a breadth-first search (BFS) on an object and its attributes, searching for a specific attribute with the given name. The search is done iteratively, exploring all the attributes of the objects in a breadth-first order, until the desired attribute is found or all objects have been traversed without finding it.

Parameters:
  • root (Any) – Root of search.

  • attr (str) – Attribute name to search.

Returns:

Any – The attribute with name attr found in search.

Raises:

AttributeError – When could not find the attribute.

Examples

>>> def fun():
...     pass
>>> fun.hello = lambda x: x * 2
>>> fun.hello.again = lambda x: x / 4
>>> fun.hallo = lambda x: x - 7
>>> fun.hallo.wieder = lambda x: x**3
>>> fun.hola = lambda x: x + 2
>>> fun.hola.otravez = lambda x: x * 8
>>> bfs_attr_search(fun, "again")
<function <lambda> at ???>
>>> bfs_attr_search(fun, "again")(20)
5.0