Module:Sandbox/CXuesong/Translations: Difference between revisions

Content deleted Content added
CXuesong (talk | contribs)
No edit summary
CXuesong (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 6:
fr = "La Guerre des Clans",
hu = "Harcosok Törzse",
jpja = "ウォーリアーズ",
ko = "고양이 전사들",
lt = "Klanų Kariai",
Line 24:
fr = "chat",
hu = "macska",
jpja = "猫",
ko = "고양이",
lt = "katinas",
Line 42:
fr = "chef",
hu = "vezér",
jpja = "族長",
ko = "지도자",
lt = "vadas",
Line 60:
fr = "Feuille de Lune",
hu = nil,
jpja = "リーフプール",
ko = nil,
lt = nil,
Line 78:
fr = "Étoile Bleue",
hu = "Kékcsillag",
jpja = "ブルスター",
ko = nil,
lt = nil,
Line 92:
}
 
-- known languages (except for English)
 
local languages = {
Line 121:
}
 
local ENGLISH_TAG = "en"
function orderedLanguages()
local namesENGLISH = {}"English"
 
function orderedKeys(dict)
local keys = {}
local result = {}
for k, v in pairs(languagesdict) do
tablestable.insert(nameskeys, k)
end
table.sort(nameskeys)
for i, k in ipairs(nameskeys) do
table.insert(result, k)
end
return result
end
 
function NZ(value, valueifNil)
if value == nil then return valueifNil end
return value
end
 
-- the module
local p = { }
 
function p.getLanguageName(frame)
return languages(frame.args[1])
end
 
-- Returns the translation of specific keyword (English)
-- with the provided language tag,
-- or nil, if no such translation is found.
function p.translate(key, languageframe)
local term = frame.args[1]
local language = frame.args[2]
-- Bypass English.
if language == "en"ENGLISH_TAG then return key end
return translations[key][language]
end
 
-- Generates a full glossary
function p.glossaryglossaryTable()
local colhdr = mw.html.create("table")
:attr("class", "wikitable")
:css("float", "left")
:css("margin", "0")
:css("margin-right", "-1px")
local body = mw.html.create("table")
local body = :attrmw.html.create("class", "wikitablediv")
:css("overflow-x", "auto")
:css("white-space", "nowrap")
:tag("trtable")
:attr("class", "wikitable")
local langs = orderedLanguages()
:css("margin", "0")
:tag("tr")
colhdr:tag("tr"):tag("th"):wikitext(ENGLISH)
local langs = orderedLanguagesorderedKeys(languages)
for i, langTag in ipairs(langs) do
body:tag("th"):wikitext(languages[langTag])
end
body = body:done();
forlocal key,transKeys trans= in pairsorderedKeys(translations) do
for i, key in ipairs(transKeys) do
colhdr:tag("tr"):tag("th"):wikitext(key)
body = body:tag("tr")
local trans = translations[key]
for i, langTag in ipairs(langs) do
t = trans[langTag]
Line 173 ⟶ 193:
--print(key)
end
body = body:allDone()
local div = mw.html.create("div")
:node(colhdr)
Line 179 ⟶ 200:
end
 
-- Generates a table of translations of a specific English term.
-- Returns nil if no such term exists in the dictionary.
function p.translationTable(frame)
local term = frame.args[1]
local trans = translations[term]
if trans == nil then return nil end
local body = mw.html.create("table")
:attr("class", "wikitable")
local transKeys = orderedKeys(trans)
body:tag("tr")
:tag("th")
:wikitext(ENGLISH)
:done()
:tag("th")
:wikitext(term)
:done()
for i, key in ipairs(transKeys) do
body:tag("tr")
:tag("th")
:wikitext(NZ(languages[key], key))
:done()
:tag("td")
:wikitext(NZ(trans[key], "-"))
:done()
end
return tostring(body)
end
--print(p.glossary())