perf(l10n): add zero-arg fast path to translate

_l10n:translate now short-circuits the common no-argument case
(select('#', ...) == 0), returning the translation directly and skipping
the {...} allocation, the tostring loop, and safeFormat. Behavior matches
the slow path: a successful no-arg lookup already returned the raw value,
and missing/invalid entries fall back to the key. Cherry-picked from
phase2-lua50-sweep.
This commit is contained in:
Xurkon
2026-06-08 16:25:09 -05:00
parent 700445c248
commit c7af49d8bd
2 changed files with 28 additions and 0 deletions
+27
View File
@@ -191,6 +191,33 @@ function _l10n:translate(key, ...)
return ""
end
key = tostring(key)
local argCount = select("#", ...)
if argCount == 0 then
local translationEntry = l10n.translations[key]
if not translationEntry then
if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translations for '" .. tostring(key) .. "' are missing completely!") end
return key
end
local translationValue = translationEntry[locale]
if (not translationValue) then
if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translations for '" .. tostring(key) .. "' are missing the entry for language" , locale, "!") end
return key
end
if translationValue == true then
-- Fallback to enUS which is the key
return key
end
if type(translationValue) ~= "string" then
if (Questie.db.profile.debugEnabled) then Questie:Debug(Questie.DEBUG_ELEVATED, "ERROR: Translation for '" .. tostring(key) .. "' is not a string!") end
return key
end
return translationValue
end
local args = {...}
for i, v in ipairs(args) do