A pure lua library for management of strings geared towards localization purposes.
- Hot swap in real time of strings
- Simple API
- Lightweight
- Protected mode
- Configurable
- 📡 Get a copy of language.lua from the Official Repository or From Luarocks
- 💾 Copy
language.luawhere you like to use it, or just on the root directory of the project - ⚙ Add it to your project like this:
local language = require("path/to/language")
- 📃 Pass a path or table containing the data
- Method 1: The strings are defined internally
local english = { welcome = "Welcome back!", menu = { title = "Main menu:", option1 = { name = "Start", description = "Description of start" } }, debugmenu = { title = "Hello world" } } local spanish = { welcome = "Bienvenido de regreso!", menu = { title = "Menú principal:", option1 = { name = "Iniciar", description = "Descripcion de iniciar" } } } language.loadLanguage("english", english) language.loadLanguage("spanish", spanish) language.setLanguage("english") language.setBackupLanguage("english")
- Method 2: The string are on an external file
--This will look for english.lua and spanish.lua inside the folder l10n --Those files must return a table of strings to work with language.loadLanguage("english", "l10n.english") language.loadLanguage("spanish", "l10n.spanish")
- 🖨️ Every time you want tell something to the user, do it by the
getStringfunction.print(language.getString("welcome")) print(language.getString("menu.title")) print(language.getString("menu.option1.name")) print(language.getString("menu.option1.description")) language.setLanguage("spanish") print(language.getString("welcome")) print(language.getString("menu.title")) print(language.getString("menu.option1.name")) print(language.getString("menu.option1.description")) --English: -->Welcome back! -->Main menu: -->Start -->Description of start --Spanish: -->Bienvenido de regreso! -->Menú principal -->Iniciar -->Descripcion de iniciar
- 💎 Profit. For more in depth documentation take a look down below.
-
language.setProtectedMode(bool)Enabled by default, Make protected calls for catching runtime errors.- Parameters:
- *Boolean
boolEnable true, Disable false.
- *Boolean
- Returns:
- nothing
- Parameters:
-
language.setIsoleatedMode(bool)Enabled by default, when loading a string from an external lua file isolate said lua file for accessing the environment, can be disabled to do wacky stuff for dynamic and or procedural string generation.- Parameters:
- *Boolean
boolEnable true, Disable false.
- *Boolean
- Returns:
- nothing
- Parameters:
-
language.setSanitizeOutput(bool)Enabled by default, when calling getString filter out any type that is not in thesanitizeFilterwhitelist.- Parameters:
- *Boolean
boolEnable true, Disable false.
- *Boolean
- Returns:
- nothing
- Parameters:
-
language.setSanitizeOutputFilters(filterList)Set what typesgetStringis allowed to output whensetSanitizeOutputis enabled, by default they arestring,numberandtable- Parameters:
- Table
filterListA table containing strings that represent a type likestring,function,number,nil,tableoruserdatawhen given the literallnilit will assume default config wich is{"string", "table", "number"}.
- Table
- Returns:
- nothing
- Parameters:
-
language.setLanguage(name)Sets the current language to use- Parameters:
- *String
nameThe current language chosen.
- *String
- Returns:
- nothing
- Parameters:
-
language.setPrintErrors(bool)Enabled by default, When in protected mode, print error that are being caught.- Parameters:
- *Boolean
boolEnable true, Disable false.
- *Boolean
- Returns:
- nothing
- Parameters:
-
language.loadLanguage(name, data)Load a table containing the strings into memory.- Parameters:
- *String
nameWhat name will have the key where the data will be saved. - *String, Table
data- *String
dataPath to the file to look for loading the table. - *Table
dataTable containing the strings already loaded.
- *String
- *String
- Returns:
- nothing
- Parameters:
-
language.getString(stringKey, languageKey)- Parameters:
- *String
stringKeyString identification key, the key can be nested in other keys using the.separator eg:menu.main.title - String
languageKeywhen set this will override the current language only for this call to the specified one, if not found it will just ignore it.
- *String
- Returns:
- *String
stringwhen used correctly this will always return a String, it may return a table when thekeypoints to said table, but also may point to a function or undefined types ifsetSanitizeOutputis set tofalse.
- *String
- Parameters:
-
lang.getLocalizationData()- Parameters:
- nothing
- Returns:
- *Table
localizationThis contains the strings loaded, although not encouraged this can be manipulated directly.
- *Table
- Parameters:
-
lang.getActualLanguageData()- Parameters:
- nothing
- Returns:
- *Table
actualLangReturns what is effectivelylocalization[systemLanguage].
- *Table
- Parameters:
-
lang.getBackupLanguageData()- Parameters:
- nothing
- Returns:
- *Table
backupLangThis is a fallback table where akeywill be searched whenactualLanghas no defined suchkey. return backupLang end
- *Table
- Parameters:
-
lang.getLanguage()Get the current language that this library tries to look for when asked of a key ongetString.- Parameters:
- nothing
- Returns:
- *String
systemLanguageWhat is the language that is set.
- *String
- Parameters: