diff --git a/scripts/Locales/enUS.lua b/scripts/Locales/enUS.lua new file mode 100644 index 0000000..2a61ba0 --- /dev/null +++ b/scripts/Locales/enUS.lua @@ -0,0 +1,10 @@ +local Tinkr, Bastion = ... + +if not Bastion.Locale.ShouldLoad("enUS") then return end + +local L = {} + +L["Tinkr"] = "Tinkr" +L["Bastion"] = "Bastion" + +Bastion.Locale.SetTable(L) diff --git a/src/Locale/Locale.lua b/src/Locale/Locale.lua index af216a4..c62c7d2 100644 --- a/src/Locale/Locale.lua +++ b/src/Locale/Locale.lua @@ -3,4 +3,47 @@ local Tinkr, Bastion = ... local Locale = {} Locale.__index = Locale +local private = { + locale = nil, + tbl = nil, + hasNoLocaleTable = nil +} + +private.locale = function() + local locale = GAME_LOCALE or GetLocale() + if locale == "enGB" then + locale = "enUS" + end + return locale +end + +function Locale.GetTable() + assert(private.tbl) + return private.tbl +end + +function Locale.ShouldLoad(locale) + assert(private.locale) + return locale == private.locale +end + +function Locale.SetTable(tbl) + assert(not private.tbl) + private.tbl = setmetatable(tbl, { + __index = function(t, k) + local v = tostring(k) + if not private.hasNoLocaleTable then + error(string.format("Locale string does not exist: \"%s\"", v)) + end + rawset(t, k, v) + return v + end, + __newindex = function() + error("Cannot write to the locale table") + end, + }) +end + +Locale.SetTable({}) + return Locale