Skip to main content

LocalizedTextUtils

Localized text utils which changes translationKey structures to shared locations

Types​

TranslationArgs​

type TranslationArgs = {[string]: LocalizedTextData | number | string}

Valid translation args

LocalizedTextData​

interface LocalizedTextData {
translationKey: string
translationArgs: TranslationArgs
}

Valid localized text data

Functions​

create​

LocalizedTextUtils.create(
translationKey: string,
translationArgs: TranslationArgs
) → LocalizedTextData

Creates a new localizedtextdata

isLocalizedText​

LocalizedTextUtils.isLocalizedText(data: any) → boolean

Returns whether the given argument is localized text

formatByKeyRecursive​

LocalizedTextUtils.formatByKeyRecursive(
translator: Translator | JSONTranslator,
translationKey: string,
translationArgs: TranslationArgs?,
extraArgs: table?
) → string

Recursively formats the translated text.

observeFormatByKeyRecursive​

LocalizedTextUtils.observeFormatByKeyRecursive(
translator: Translator | JSONTranslator,
translationKey: string,
translationArgs: TranslationArgs?,
extraArgs: table?
) → Observable<string>

Observes the recursively formatted translated text.

localizedTextToString​

LocalizedTextUtils.localizedTextToString(
translator: Translator | JSONTranslator,
localizedText: LocalizedTextData,
extraArgs: table?
) → string

Recursively formats the translated text

fromJSON​

LocalizedTextUtils.fromJSON(text: string) → LocalizedTextData?

Converts from JSON

toJSON​

LocalizedTextUtils.toJSON(localizedText: LocalizedTextData) → string?

Converts to JSON

setFromAttribute​

LocalizedTextUtils.setFromAttribute(
obj: Instance,
attributeName: string,
translationKey: string,
translationArgs: TranslationArgs
) → LocalizedTextData

Sets the translation data as an attribute on an instance.

getFromAttribute​

LocalizedTextUtils.getFromAttribute(
obj: Instance,
attributeName: string
) → LocalizedTextData

Reads the data from the attribute

getTranslationFromAttribute​

LocalizedTextUtils.getTranslationFromAttribute(
translator: Translator | JSONTranslator,
obj: Instance,
attributeName: string,
extraArgs: table?
) → string?

Gets the translation from a given object's attribute

initializeAttribute​

LocalizedTextUtils.initializeAttribute(
obj: Instance,
attributeName: string,
defaultTranslationKey: string,
defaultTranslationArgs: table?
) → ()

Ensures an attribute is defined if nothing is there

observeTranslation​

LocalizedTextUtils.observeTranslation(
translator: Translator | JSONTranslator,
obj: Instance,
attributeName: string,
extraArgs: table?
) → Observable<string?>

Returns the translated string from the given object

Show raw api
{
    "functions": [
        {
            "name": "create",
            "desc": "Creates a new localizedtextdata",
            "params": [
                {
                    "name": "translationKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "translationArgs",
                    "desc": "",
                    "lua_type": "TranslationArgs"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "LocalizedTextData"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 35,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "isLocalizedText",
            "desc": "Returns whether the given argument is localized text",
            "params": [
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 50,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "formatByKeyRecursive",
            "desc": "Recursively formats the translated text.",
            "params": [
                {
                    "name": "translator",
                    "desc": "",
                    "lua_type": "Translator | JSONTranslator"
                },
                {
                    "name": "translationKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "translationArgs",
                    "desc": "",
                    "lua_type": "TranslationArgs?"
                },
                {
                    "name": "extraArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 65,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "observeFormatByKeyRecursive",
            "desc": "Observes the recursively formatted translated text.",
            "params": [
                {
                    "name": "translator",
                    "desc": "",
                    "lua_type": "Translator | JSONTranslator"
                },
                {
                    "name": "translationKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "translationArgs",
                    "desc": "",
                    "lua_type": "TranslationArgs?"
                },
                {
                    "name": "extraArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 106,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "localizedTextToString",
            "desc": "Recursively formats the translated text",
            "params": [
                {
                    "name": "translator",
                    "desc": "",
                    "lua_type": "Translator | JSONTranslator"
                },
                {
                    "name": "localizedText",
                    "desc": "",
                    "lua_type": "LocalizedTextData"
                },
                {
                    "name": "extraArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 145,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "fromJSON",
            "desc": "Converts from JSON",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "LocalizedTextData?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 161,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "toJSON",
            "desc": "Converts to JSON",
            "params": [
                {
                    "name": "localizedText",
                    "desc": "",
                    "lua_type": "LocalizedTextData"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 180,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "setFromAttribute",
            "desc": "Sets the translation data as an attribute on an instance.",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "translationKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "translationArgs",
                    "desc": "",
                    "lua_type": "TranslationArgs"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "LocalizedTextData"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 195,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "getFromAttribute",
            "desc": "Reads the data from the attribute",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "LocalizedTextData"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 209,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "getTranslationFromAttribute",
            "desc": "Gets the translation from a given object's attribute",
            "params": [
                {
                    "name": "translator",
                    "desc": "",
                    "lua_type": "Translator | JSONTranslator"
                },
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "extraArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 229,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "initializeAttribute",
            "desc": "Ensures an attribute is defined if nothing is there",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "defaultTranslationKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "defaultTranslationArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 249,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "observeTranslation",
            "desc": "Returns the translated string from the given object",
            "params": [
                {
                    "name": "translator",
                    "desc": "",
                    "lua_type": "Translator | JSONTranslator"
                },
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "extraArgs",
                    "desc": "",
                    "lua_type": "table?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<string?>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 270,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "TranslationArgs",
            "desc": "Valid translation args",
            "lua_type": "{ [string]: LocalizedTextData | number | string }",
            "source": {
                "line": 20,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        },
        {
            "name": "LocalizedTextData",
            "desc": "Valid localized text data",
            "fields": [
                {
                    "name": "translationKey",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "translationArgs",
                    "lua_type": "TranslationArgs",
                    "desc": ""
                }
            ],
            "source": {
                "line": 28,
                "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
            }
        }
    ],
    "name": "LocalizedTextUtils",
    "desc": "Localized text utils which changes translationKey structures to shared locations",
    "source": {
        "line": 5,
        "path": "src/localizedtextutils/src/Shared/LocalizedTextUtils.lua"
    }
}