Files
Leon.Schmidt e58f1b6c18 FIX - complete phone locale fallback
Resolve configured and regional locales through a centralized English fallback for Lua and NUI consumers. Complete the German and English app translation keys, localize remaining picker and attachment copy, and add contract tests that detect missing locale entries.
2026-08-17 15:01:57 +02:00

48 lines
1.3 KiB
Lua

Config = Config or {}
Locales = Locales or {}
SkyPhoneLocales = SkyPhoneLocales or {}
local resolved_locales = {}
local function clone_locale(value)
if type(value) ~= "table" then
return value
end
local copied = {}
for key, nested in pairs(value) do
copied[key] = clone_locale(nested)
end
return copied
end
local function merge_locale(target, values)
for key, value in pairs(values) do
if type(value) == "table" and type(target[key]) == "table" then
merge_locale(target[key], value)
else
target[key] = clone_locale(value)
end
end
end
function SkyPhoneLocales.Resolve(requested_locale)
local normalized = type(requested_locale) == "string" and requested_locale:lower():gsub("_", "-") or "en"
local base = normalized:match("^([^-]+)") or "en"
local locale_name = Locales[normalized] and normalized or (Locales[base] and base or "en")
local selected = Locales[locale_name] or Locales.en or {}
local english = Locales.en or {}
if selected == english then
return english, "en"
end
if not resolved_locales[locale_name] then
resolved_locales[locale_name] = clone_locale(english)
merge_locale(resolved_locales[locale_name], selected)
end
return resolved_locales[locale_name], locale_name
end