API:LoadStringTable
From RoR Wiki
UI Lua API · StringTable functions
Version: WAR 1.4.8
Loads a localized string table from the game data so its strings can be looked up by the UI.
LoadStringTable(tableName, directory, fileName, cacheDirectory, luaTableName)
Arguments
- tableName
string– Name to register the table under. Used later with UnloadStringTable and the string lookup functions.- directory
string– Folder of the string file, for example"data/strings/<LANG>".- fileName
string– Name of the string file in that folder, for example"pregame.txt".- cacheDirectory
string– Folder for the client's cache files of the table, for example"cache/<LANG>".- luaTableName
string– Path of a Lua table to fill with the string keys, for example"StringTables.Pregame". Pass""for none.
Returns
Nothing.
Details
- The file path is
directoryandfileNamejoined with a/(none is added ifdirectoryalready ends with one). - The stock UI writes
<LANG>in the folder names; the client replaces it with the current language. - The cache file is
cacheDirectory/tableName.cache. WhenluaTableNameis not empty, a second cache filecacheDirectory/tableName.cache2is used as well. tableNameis compared without regard to case. A name that is already loaded is refused with an error.- When
luaTableNameis not empty, the Lua table at that path gets one number field per string key, named after the key. The stock UI uses these fields to look strings up, for exampleGetPregameString(StringTables.Pregame.LABEL_CANCEL). - If loading fails, the table is not registered and an error is raised.
- The function needs at least five arguments and only reads the last five. All must be strings.
Errors
No StringTable file specified.(emptyfileName)StringTable name %s is already in use.StringTable %s: %s(loading failed; the second value is the client's reason)
Example
From interfacecore/interfacecore.lua:
LoadStringTable("Pregame", "data/strings/<LANG>", "pregame.txt", "cache/<LANG>", "StringTables.Pregame" )
LoadStringTable("Hardcoded", "data/strings/<LANG>", "hardcoded.txt", "cache/<LANG>", "" )
