Rework locale

This commit is contained in:
2025-01-26 17:43:43 +01:00
parent 62b028cf56
commit 35398ebf38
3 changed files with 226 additions and 207 deletions

View File

@@ -23,7 +23,8 @@ local function init()
---@field network HeimdallNetworkData
---@field networkMessenger HeimdallNetworkMessengerData
---@field stinkyCache HeimdallStinkyCacheData
---@field _L Localization
---@field _L fun(key: string, locale: string): string
---@field _Locale Localization
---@field VERSION string
---@field dumpTable fun(table: any, depth?: number): nil
---@field utf8len fun(input: string): number
@@ -32,6 +33,7 @@ local function init()
---@field Split fun(input: string, deliminer: string): string[]
---@field IsStinky fun(name: string): boolean
---@field Memoize fun(f: function): function
---@field GetLocaleForChannel fun(channel: string): string
---@field WhoQueryService WhoQueryService
---@field Whoer InitTable
---@field Messenger InitTable
@@ -635,6 +637,33 @@ local function init()
end
end
---@param channel string
---@return string
shared.GetLocaleForChannel = function(channel)
return Heimdall_Data.config.channelLocale[channel] or "en"
end
---@param key string
---@param locale string
---@return string
shared._L = function(key, locale)
local locale = shared._Locale[locale]
if not locale then
if Heimdall_Data.config.debug then
print(string.format("[Heimdall] Locale %s not found", tostring(locale)))
end
return key
end
local value = locale[key]
if not value then
if Heimdall_Data.config.debug then
print(string.format("[Heimdall] Key %s not found in locale %s", tostring(key), tostring(locale)))
end
return key
end
return value
end
shared.Messenger.Init()
shared.StinkyTracker.Init()
shared.AgentTracker.Init()