-
Notifications
You must be signed in to change notification settings - Fork 55
/
Locale.lua
51 lines (35 loc) · 1.45 KB
/
Locale.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local addonName, addon = ...
local ssplit, strjoin, ipairs, unpack, next = strsplittable, strjoin, ipairs,
unpack, next
addon.locale = {}
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local delim = L.delimiter
local DEBUG = false -- One of the first files loaded, so no settings
local lazyTranslationCache = {}
if DEBUG then print(addonName .. ": Processing locale: " .. GetLocale()) end
local function getForeign(text)
if not text then return end
if L[text] then return L[text] end
if lazyTranslationCache[text] then return lazyTranslationCache[text] end
if next(L.words) == nil then
-- No custom words added
lazyTranslationCache[text] = text
return text
end
if DEBUG then print("Phrase not found, looking for words") end
-- Direct text doesn't match, so iterate over phrase and lazy translate
local words = ssplit(delim, text)
-- TODO string insensitive lookups
for i, w in ipairs(words) do if L.words[w] then words[i] = L.words[w] end end
local lazyPhrase = strjoin(delim, unpack(words))
lazyTranslationCache[text] = lazyPhrase
return lazyPhrase
end
local function noop(text) return text end
local locale = GetLocale()
-- Explicitly check supported languages, default to enUS
if locale == 'zhCN' or locale == 'zhTW' or locale == 'frFR' or locale == 'koKR' then
addon.locale.Get = getForeign
else
addon.locale.Get = noop
end