mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 09:13:29 +00:00
Add locale convar and locale fallback
This commit is contained in:
+10
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user