ix.lang
Multi-language phrase support.
Helix 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. For example, in plugins/area/sh_english.lua
:
LANGUAGE = {
area = "Area",
areas = "Areas",
areaEditMode = "Area Edit Mode",
-- etc.
}
The phrases defined in these language files can be used with the L
global function:
print(L("areaEditMode"))
> Area Edit Mode
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("areaDeleteConfirm", "Test"))
> Are you sure you want to delete the area "Test"?
Phrases are also usable on the server, but only when trying to localize a phrase based on a client's preferences. The server does not have a set language. An example:
Entity(1):ChatPrint(L("areaEditMode"))
> -- "Area Edit Mode" will print in the player's chatbox
Functions
ix.lang.AddTable(language, data)
View source »Adds phrases to a language. This is used when you aren't adding entries through the files in the languages/
folder. A
common use case is adding language phrases in a single-file plugin.
Parameters
-
language
string
The ID of the language
-
data
table
Language data to add to the given language
Example Usage
ix.lang.AddTable("english", {
myPhrase = "My Phrase"
})
ix.lang.LoadFromDir(directory)
This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.
Loads language files from a directory.
Parameters
-
directory
string
Directory to load language files from