Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
m
Line 1: Line 1:
 
local p = {}
 
local p = {}
  +
  +
local utilsString = require("Module:UtilsString")
 
local utilsTable = require("Module:UtilsTable")
 
local utilsTable = require("Module:UtilsTable")
   
Line 8: Line 10:
 
end
 
end
   
function p.getString(path, ...)
+
function p.getString(path, vars)
 
local code = mw.getContentLanguage():getCode()
 
local code = mw.getContentLanguage():getCode()
 
local localeStrings = strings[code]
 
local localeStrings = strings[code]
Line 17: Line 19:
 
result = result[subkey]
 
result = result[subkey]
 
end
 
end
return result:format(...)
+
return utilsString.interpolate(result, vars)
 
end
 
end
   

Revision as of 17:00, 22 March 2020

Documentation for this module may be created at Module:I18n/Documentation

local p = {}

local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")

local strings = {}

function p.loadStrings(tbl)
	strings = utilsTable.merge({}, strings, tbl)
end

function p.getString(path, vars)
	local code = mw.getContentLanguage():getCode()
	local localeStrings = strings[code]
	local subkeys = mw.text.split(path, "%.")
	
	local result = localeStrings
	for _, subkey in ipairs(subkeys) do
		result = result[subkey]
	end
	return utilsString.interpolate(result, vars)
end

return p