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, CommonLocalizedStringSeparator]) – 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 combine_localized_strings(identifier_list, separator=CommonLocalizedStringSeparator.NO_SEPARATOR)

Combine multiple localized strings by a separator.

Parameters:
  • identifier_list (Union[int, str, LocalizedString, CommonStringId, CommonLocalizedStringSeparator]) – A collection of identifiers to locate LocalizedStrings with, text that will be turned into a LocalizedString and combined with the other strings in the collection.
  • separator (CommonLocalizedStringSeparator, optional) – The separator to use when combining the strings. Default is to combine all of the strings by no separator, i.e. an empty space.
Returns:

A localized string with all Localized Strings combined by the specified separator.

Return type:

LocalizedString

static combine_localized_strings_with_comma_space_and(identifier_list)

Combine multiple localized strings and formulate a string that is of format “{0.String}”, “{0.String} and {1.String}”, or “{0.String}, and {1.String}”. With {0.String} being the first strings in the collection and {1.String} being the last string in the collection.

Note

Example: [‘one’] will turn into “one”. [‘one’, ‘two’] will turn into “one and two”. [‘one’, ‘two’, ‘three’] will turn into “one, two, and three”.

Parameters:identifier_list (Union[int, str, LocalizedString, CommonStringId, CommonLocalizedStringSeparator]) – A collection of identifiers to combine.
Returns:A localized string with all Localized Strings combined with a “comma space and” separator.
Return type:LocalizedString
static combine_localized_strings_with_comma_space_or(identifier_list)

Combine multiple localized strings and formulate a string that is of format “{0.String}”, “{0.String} or {1.String}”, or “{0.String}, or {1.String}”. With {0.String} being the first strings in the collection and {1.String} being the last string in the collection.

Note

Example: [‘one’] will turn into “one”. [‘one’, ‘two’] will turn into “one or two”. [‘one’, ‘two’, ‘three’] will turn into “one, two, or three”.

Parameters:identifier_list (Union[int, str, LocalizedString, CommonStringId, CommonLocalizedStringSeparator]) – A collection of identifiers to combine.
Returns:A localized string with all Localized Strings combined with a “comma space or” separator.
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, CommonLocalizedStringSeparator]) – An identifier to locate a LocalizedString with, text that will be turned into a LocalizedString, or a LocalizedString itself.
  • tokens (Iterator[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, CommonLocalizedStringSeparator]) – The text that will be displayed.
  • tooltip_tokens (Iterator[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, CommonLocalizedStringSeparator]) – 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
ORANGE = 2567694686
RED = 835489330
YELLOW = 3457894271