Localization (String Table Manipulation)

LocalizedStrings are created from text inside StringTables within package files.

Localization Utils

class CommonLocalizationUtils

Bases: object

Utilities for handling localization strings.

Note

Localized Strings are the python equivalent of values within a StringTable.

class LocalizedTooltip(string_id, *tokens)

Bases: sphinx.ext.autodoc.importer._MockObject

A LocalizedTooltip used when displaying tooltips.

Parameters:
  • string_id (Union[int, str, LocalizedString, CommonStringId]) – The text that will display in the tooltip.
  • tokens (Any) – A collection of objects to format into the string_id
static colorize(localized_string, text_color=CommonLocalizedStringColor.DEFAULT)

Set the text color of a LocalizedString.

Parameters:
  • localized_string (LocalizedString) – The LocalizedString to set the text color of.
  • text_color (CommonLocalizedStringColor) – The text will become this color.
Returns:

A LocalizedString with text in the specified color.

Return type:

LocalizedString

static create_from_int(identifier, *tokens)

Locate a LocalizedString by an identifier and format tokens into it.

Parameters:
  • identifier (int) – A decimal number that identifies an existing LocalizedString.
  • tokens (Iterator[Any]) – A collection of objects to format into the LocalizedString. (Example types: LocalizedString, str, int, etc.)
Returns:

A LocalizedString with the specified tokens formatted into it.

Return type:

LocalizedString

static create_from_string(string_text)

Create a LocalizedString from a string.

Parameters:string_text (str) – The string to localize. The resulting LocalizedString will be ‘{0.String}’
Returns:A LocalizedString created from the specified string.
Return type:LocalizedString
static create_localized_string(identifier, tokens=(), localize_tokens=True, text_color=CommonLocalizedStringColor.DEFAULT)

Create a LocalizedString formatted with the specified tokens.

Parameters:
  • identifier (Union[int, str, LocalizedString, CommonStringId]) – An identifier to locate a LocalizedString with, text that will be turned into a LocalizedString, or a LocalizedString itself.
  • tokens (Iterable[Any]) – A collection of objects to format into the localized string. (They can be anything. LocalizedString, str, int, SimInfo, just to name a few)
  • localize_tokens (bool) – If True, the specified tokens will be localized. If False, the specified tokens will be formatted into the LocalizedString as they are. Default is True
  • text_color (CommonLocalizedStringColor) – The color the text will be when displayed.
Returns:

A localized string ready for display.

Return type:

LocalizedString

static create_localized_tooltip(tooltip_text, tooltip_tokens=())

Create a LocalizedTooltip use this when you wish to display a tooltip on various things.

Parameters:
  • tooltip_text (Union[int, str, LocalizedString, CommonStringId]) – The text that will be displayed.
  • tooltip_tokens (Iterable[Any], optional) – A collection of objects to format into the localized string. (They can be anything. LocalizedString, str, int, SimInfo, just to name a few)
Returns:

A tooltip ready for display.

Return type:

LocalizedTooltip

static get_localized_string_hash(localized_string)

Retrieve the hash value of a Localized String.

Parameters:localized_string (LocalizedString) – An instance of a Localized String.
Returns:The hash value of the Localized String or 0 if a problem occurs.
Return type:int

Tooltips

class LocalizedTooltip(string_id, *tokens)

Bases: sphinx.ext.autodoc.importer._MockObject

A LocalizedTooltip used when displaying tooltips.

Parameters:
  • string_id (Union[int, str, LocalizedString, CommonStringId]) – The text that will display in the tooltip.
  • tokens (Any) – A collection of objects to format into the string_id

Colors

class CommonLocalizedStringColor

Bases: sims4communitylib.enums.enumtypes.common_int.CommonInt

Used to set the text color of LocalizedString.

See the CommonLocalizationUtils.colorize() function for more details.

BLUE = 1505840180
DEFAULT = -1
GREEN = 3458194999
RED = 835489330