Language¶
Language helpers for loading localization files, registering translation tables, resolving localized strings, and caching formatted localization output.
Overview
lia.lang.loadFromDir(directory)View Source
Purpose
Loads language files from a directory and stores their localization entries under `lia.lang.stored`.
Realm
Shared
Parameters
string directory The directory path containing language Lua files to include.
Example Usage
lia.lang.loadFromDir("lilia/gamemode/languages")
lia.lang.addTable(name, tbl)View Source
Purpose
Adds or merges localization entries into a named language table and clears the localization cache.
Realm
Shared
Parameters
string name The language identifier to add entries to.
table tbl A table of localization keys and values to register.
Example Usage
lia.lang.addTable("english", {
welcomeMessage = "Welcome, %s."
})
lia.lang.getLanguages()View Source
Purpose
Returns a sorted list of loaded language names.
Realm
Shared
Returns
table A sorted array of loaded language names with the first character capitalized.
Example Usage
for _, language in ipairs(lia.lang.getLanguages()) do
print(language)
end
lia.lang.generateCacheKey(lang, key)View Source
Purpose
Generates a cache key for a language lookup using the language, localization key, and formatting arguments.
Realm
Shared
Parameters
string lang The language identifier used for the lookup.
string key The localization key being resolved.
Returns
string The generated cache key.
Example Usage
local cacheKey = lia.lang.generateCacheKey("english", "welcomeMessage", client:Name())
lia.lang.cleanupCache()View Source
lia.lang.clearCache()View Source
lia.lang.getLocalizedString(key)View Source
Purpose
Resolves and formats a localization string for the currently configured language.
Realm
Shared
Parameters
string key The localization key to resolve.
Returns
string The resolved and formatted localization string, or the key itself when no localization entry exists or formatting fails.
Example Usage
client:notifyInfo(lia.lang.getLocalizedString("welcomeMessage", client:Name()))
print(L("welcomeMessage", client:Name()))
lia.lang.resolveToken(value)View Source
Purpose
Resolves localization tokens that begin with `@` while leaving all other values unchanged.
Realm
Shared
Parameters
any value The value to inspect for a localization token.
Returns
any The resolved localization string for `@` tokens, an empty string for an empty token, or the original value when it is not a localization token.
Example Usage
local text = lia.lang.resolveToken("@welcomeMessage", client:Name())
Hooks
Library-specific hooks documented for this library.