Add locale convar and locale fallback

This commit is contained in:
David Malchin
2022-09-04 00:46:21 +03:00
parent aadf09937e
commit 1a3aa824fa
34 changed files with 231 additions and 127 deletions
+10 -1
View File
@@ -32,7 +32,13 @@ end
--- @return Locale
function Locale:new(opts)
setmetatable(self, Locale)
self.warnOnMissing = opts.warnOnMissing or true
self.fallback = opts.fallbackLang and Locale.new({}, {
warnOnMissing = false,
phrases = opts.fallbackLang.phrases,
}) or false
self.warnOnMissing = type(opts.warnOnMissing) ~= 'boolean' and true or opts.warnOnMissing
self.phrases = {}
self:extend(opts.phrases or {})
@@ -98,6 +104,9 @@ function Locale:t(key, subs)
if self.warnOnMissing then
print(('^3Warning: Missing phrase for key: "%s"'):format(key))
end
if self.fallback then
return self.fallback:t(key, subs)
end
result = key
end