Logo

DIVERSITY

Documentation

Library

Language

Manage localization keys, retrieve translated strings with optional formatting, and clear language caches.

Shared Functions


Locale

Retrieves the localized string for the given key, optionally formatting it with additional arguments.

client.lua
-- Retrieve localized text for a simple key
local text = dLib.Language.Locale('success')
print('Localized text:', text)

-- Retrieve localized text for a nested key (category.button)
local text = dLib.Language.Locale('buttons.ok')
print(text)

-- Retrieve localized text with multiple formatting arguments
local text = dLib.Language.Locale('notifications.item_purchased', 'Health Kit', 50)
print(text) -- Output: You purchased Health Kit for $50.
ArgumentTypeDescription
key
string
The localization key to retrieve the text for. Can be a simple key or a nested key like "category.button".
args?
any
Optional formatting arguments to substitute into the localized string. Can be any number of values to replace format specifiers in the text.
Returned DataTypeDescription
text
string
The localized text or the key if not found.

Clear

Clears the language cache or only the specified dictionary for the current resource.

client.lua
-- Clear the entire language cache for the current resource
dLib.Language.Clear()

-- Clear only the English ('en') dictionary from the language cache
dLib.Language.Clear('en')
ArgumentTypeDescription
key?
string
Optional language code to clear a specific dictionary; omit to clear the entire language cache.

Was this page helpful?