mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
refactor(es_extended/locale): refactor Translate fun
This commit is contained in:
@@ -3,21 +3,23 @@ Locales = {}
|
||||
function Translate(str, ...) -- Translate string
|
||||
if not str then
|
||||
error(("Resource ^5%s^1 You did not specify a parameter for the Translate function or the value is nil!"):format(GetInvokingResource() or GetCurrentResourceName()))
|
||||
return "Given translate function parameter is nil!"
|
||||
end
|
||||
if Locales[Config.Locale] then
|
||||
if Locales[Config.Locale][str] then
|
||||
return string.format(Locales[Config.Locale][str], ...)
|
||||
elseif Config.Locale ~= "en" and Locales["en"] and Locales["en"][str] then
|
||||
return string.format(Locales["en"][str], ...)
|
||||
else
|
||||
return "Translation [" .. Config.Locale .. "][" .. str .. "] does not exist"
|
||||
|
||||
local translations = Locales[Config.Locale]
|
||||
if not translations then
|
||||
-- Fall back to English translation if the current locale is not found
|
||||
if Locales.en and Locales.en[str] then
|
||||
return Locales.en[str]:format(...)
|
||||
end
|
||||
elseif Config.Locale ~= "en" and Locales["en"] and Locales["en"][str] then
|
||||
return string.format(Locales["en"][str], ...)
|
||||
else
|
||||
return "Locale [" .. Config.Locale .. "] does not exist"
|
||||
|
||||
return ("Locale [%s] does not exist"):format(Config.Locale)
|
||||
end
|
||||
|
||||
if translations[str] then
|
||||
return translations[str]:format(...)
|
||||
end
|
||||
|
||||
return ("Translation [%s][%s] does not exist"):format(Config.Locale, str)
|
||||
end
|
||||
|
||||
function TranslateCap(str, ...) -- Translate string first char uppercase
|
||||
|
||||
Reference in New Issue
Block a user