"Added private variables and functions to Locale.lua, including locale detection, table management, and error handling."

CiscOH Bellic 2 years ago
parent 567a877b36
commit 60e644d6aa
  1. 10
      scripts/Locales/enUS.lua
  2. 43
      src/Locale/Locale.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)

@ -3,4 +3,47 @@ local Tinkr, Bastion = ...
local Locale = {} local Locale = {}
Locale.__index = 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 return Locale

Loading…
Cancel
Save