Skip to main content

ResolveLocaleUtils

Shared locale-id parsing and resolution. Keeps the "given a locale like en-us, what do we actually use?" logic in one place so number formatting, dialog pacing, and any other locale-sensitive feature resolve identically.

Locale ids follow BCP-47-ish shapes: a language subtag, then optional script and/or region subtags separated by - (or sometimes _), e.g. en, en-us, pt-br, zh-Hant-TW. Matching is case-insensitive.

Functions

getLanguageSubtag

ResolveLocaleUtils.getLanguageSubtag(localestring?) → string?

Returns the lowercased primary language subtag, or nil when the input has no language subtag (nil, non-string, empty, or leading punctuation/digits).

ResolveLocaleUtils.getLanguageSubtag("en-us") --> "en"
ResolveLocaleUtils.getLanguageSubtag("zh_Hant_TW") --> "zh"
ResolveLocaleUtils.getLanguageSubtag("PT-BR") --> "pt"
ResolveLocaleUtils.getLanguageSubtag(nil) --> nil

isTraditionalChinese

ResolveLocaleUtils.isTraditionalChinese(localestring?) → boolean

Whether a Chinese locale is Traditional. hant, and the tw / hk / mo regions are Traditional; everything else (hans, cn, sg, bare zh) is Simplified. Only meaningful for zh locales.

resolveClosestKey

ResolveLocaleUtils.resolveClosestKey(
localestring?,
availableLocales{[string]T}
) → string?

Resolves a locale to the best-matching key present in availableLocales:

  1. Exact (case-insensitive) match.
  2. Chinese Traditional/Simplified routing to whichever variant keys exist.
  3. Closest key sharing the language subtag (smallest key, so the pick is deterministic), so e.g. en-gb falls back to en-us and es-mx to es-es rather than to an unrelated default.

Returns nil when nothing shares the language subtag; callers apply their own default in that case.

Show raw api
{
    "functions": [
        {
            "name": "getLanguageSubtag",
            "desc": "Returns the lowercased primary language subtag, or nil when the input has no\nlanguage subtag (nil, non-string, empty, or leading punctuation/digits).\n\n```lua\nResolveLocaleUtils.getLanguageSubtag(\"en-us\") --> \"en\"\nResolveLocaleUtils.getLanguageSubtag(\"zh_Hant_TW\") --> \"zh\"\nResolveLocaleUtils.getLanguageSubtag(\"PT-BR\") --> \"pt\"\nResolveLocaleUtils.getLanguageSubtag(nil) --> nil\n```",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 40,
                "path": "src/clienttranslator/src/Shared/Utils/ResolveLocaleUtils.lua"
            }
        },
        {
            "name": "isTraditionalChinese",
            "desc": "Whether a Chinese locale is Traditional. `hant`, and the `tw` / `hk` / `mo`\nregions are Traditional; everything else (`hans`, `cn`, `sg`, bare `zh`) is\nSimplified. Only meaningful for `zh` locales.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 63,
                "path": "src/clienttranslator/src/Shared/Utils/ResolveLocaleUtils.lua"
            }
        },
        {
            "name": "resolveClosestKey",
            "desc": "Resolves a locale to the best-matching key present in `availableLocales`:\n\n1. Exact (case-insensitive) match.\n2. Chinese Traditional/Simplified routing to whichever variant keys exist.\n3. Closest key sharing the language subtag (smallest key, so the pick is\n   deterministic), so e.g. `en-gb` falls back to `en-us` and `es-mx` to `es-es`\n   rather than to an unrelated default.\n\nReturns nil when nothing shares the language subtag; callers apply their own\ndefault in that case.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                },
                {
                    "name": "availableLocales",
                    "desc": "",
                    "lua_type": "{ [string]: T }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 92,
                "path": "src/clienttranslator/src/Shared/Utils/ResolveLocaleUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "ResolveLocaleUtils",
    "desc": "Shared locale-id parsing and resolution. Keeps the \"given a locale like\n`en-us`, what do we actually use?\" logic in one place so number formatting,\ndialog pacing, and any other locale-sensitive feature resolve identically.\n\nLocale ids follow BCP-47-ish shapes: a language subtag, then optional script\nand/or region subtags separated by `-` (or sometimes `_`), e.g. `en`, `en-us`,\n`pt-br`, `zh-Hant-TW`. Matching is case-insensitive.",
    "source": {
        "line": 13,
        "path": "src/clienttranslator/src/Shared/Utils/ResolveLocaleUtils.lua"
    }
}