lia.lang
Multi-language phrase support.
Lilia has support for multiple languages, and you can easily leverage this system for use in your own schema, plugins, etc.
Languages will be loaded from the schema and any plugins in languages/sh_languagename.lua
, where languagename
is the id of a
language (english
for English, french
for French, etc). The structure of a language file is a table of phrases with the key
as its phrase ID and the value as its translation for that language. An example
LANGUAGE = {
welcomeMessage = "Welcome to the game!",
gameOver = "Game over! You won the game!",
victory = "%s achieved victory!",
}
The phrases defined in these language files can be used with the L global function:
print(L("welcomeMessage"))
> "Welcome to the game!"
All phrases are formatted with string.format, so if you wish to add some info in a phrase you can use standard Lua string formatting arguments:
print(L("victory", "Nicholas"))
> Nicholas achieved victory!
Functions
AddTable(name, tbl)
Adds a table of phrases to a language.
Parameters
-
name
String
The name of the language to add the phrases to.
-
tbl
Table
The table of phrases to add.
L(key, ...)
Retrieves a localized string based on the specified key and the default language setting.
Parameters
-
key
String
The key corresponding to the desired localized string.
-
...
Table
Additional parameters to format the localized string.
Returns
-
any
The formatted localized string.
L(key, ...)
Retrieves a localized string based on the specified key and the default language setting.
Parameters
-
key
String
The key corresponding to the desired localized string.
-
...
Table
Additional parameters to format the localized string.
Returns
-
any
The formatted localized string.
L2(key, ...)
Retrieves a localized string based on the specified key and the default language setting. Similar to L(), but returns nil if the key is not found in the language table.
Parameters
-
key
String
The key corresponding to the desired localized string.
-
...
Table
Additional parameters to format the localized string.
Returns
-
any
The formatted localized string, or nil if the key is not found.
L2(key, ...)
Retrieves a localized string based on the specified key and the default language setting. Similar to L(), but returns nil if the key is not found in the language table.
Parameters
-
key
String
The key corresponding to the desired localized string.
-
...
Table
Additional parameters to format the localized string.
Returns
-
any
The formatted localized string, or nil if the key is not found.
L3(key, langKey, ...)
Retrieves a localized string based on the specified key and language key.
Parameters
-
key
String
The key corresponding to the desired localized string.
-
langKey
String
The language key to use for localization.
-
...
Table
Additional parameters to format the localized string.
Returns
-
any
The formatted localized string, or the key if not found.
loadFromDir(directory)
Loads language files from a directory.
Parameters
-
directory
String
Directory to load language files from