More actions
No edit summary |
No edit summary |
||
(15 intermediate revisions by the same user not shown) | |||
Line 18: | Line 18: | ||
wrappers = { 'Template:Other Languages' } | wrappers = { 'Template:Other Languages' } | ||
}) | }) | ||
return p._main(args, frame) | |||
end | |||
function p._main(args, frame) | |||
local out | |||
if args["1_en"] then | |||
out = mw.html.create('div'):css { | |||
['display'] = 'flex', | |||
['column-gap'] = '15px', | |||
['flex-direction'] = 'row', | |||
['flex-wrap'] = 'wrap' | |||
} | |||
local Y = 1 | |||
local y = tostring(Y) | |||
repeat | |||
local entry = out:tag('div') | |||
entry:tag('h3'):wikitext(args[y .. '_header'] or args[y .. '_en']) | |||
entry:node(p.Table(args, frame, (y .. '_'))) | |||
Y = Y + 1 | |||
y = tostring(Y) | |||
until not args[y .. "_en"] | |||
else | |||
out = p.Table(args, frame, "") | |||
end | |||
return tostring(out) .. frame:extensionTag { name = 'references', args = { group = '•' } } | |||
end | |||
function p.Table(args, frame, prefix) | |||
local tbRows = {} | local tbRows = {} | ||
local stickTl = false | local stickTl = false | ||
Line 26: | Line 56: | ||
-- <lang>_tl: Literal Meaning | -- <lang>_tl: Literal Meaning | ||
for _, lang in ipairs(langOrder) do | for _, lang in ipairs(langOrder) do | ||
if args[lang] then | if args[prefix .. lang] then | ||
local row = {} | local row = {} | ||
row.lang = lang | row.lang = lang | ||
row.text = args[lang] | row.text = args[prefix .. lang] | ||
if lang == "pt-BR" then | if lang == "pt-BR" then | ||
row.name = "Brazilian Portuguese" | row.name = "Brazilian Portuguese" | ||
elseif lang == "sr-Cyrl" then | elseif lang == "sr-Cyrl" then | ||
row.name = "Serbian (Cyrillic)" | row.name = "Serbian<br><small>(Cyrillic)</small>" | ||
stickTl = true | stickTl = true | ||
elseif lang == "sr-Latn" then | elseif lang == "sr-Latn" then | ||
row.name = "Serbian (Latin)" | row.name = "Serbian<br><small>(Latin)</small>" | ||
elseif lang == "zh-CN" then | elseif lang == "zh-CN" then | ||
row.name = "Chinese (Simplified)" | row.lang = "zh-Hans" | ||
row.name = "Chinese<br><small>(Simplified)</small>" | |||
stickTl = true | stickTl = true | ||
elseif lang == "zh-TW" then | elseif lang == "zh-TW" then | ||
row.name = "Chinese (Traditional)" | row.lang = "zh-Hant" | ||
row.name = "Chinese<br><small>(Traditional)</small>" | |||
elseif lang == "yue" then -- ISO 693-3 | |||
row.name = "Yue Chinese" | |||
else | else | ||
row.name = languageData[lang] | row.name = languageData[lang][1] | ||
end | end | ||
row.rm = args[lang .. "_rm"] | row.rm = args[prefix .. lang .. "_rm"] | ||
if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then | if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then | ||
tbRows[#tbRows]. | tbRows[#tbRows].tl_rowspan = 2 | ||
row.tl_skip = true | |||
stickTl = false | stickTl = false | ||
elseif lang == "sr-Cyrl" or lang == "sr-Latn" then | elseif lang == "sr-Cyrl" or lang == "sr-Latn" then | ||
row.tl = args.sr_tl | row.tl = args[prefix .. "sr_tl"] | ||
row.note = args.sr_note | row.note = args[prefix .. "sr_note"] | ||
elseif lang == "zh-CN" or lang == "zh-TW" then | elseif lang == "zh-CN" or lang == "zh-TW" then | ||
row.tl = args.zh_tl | row.tl = args[prefix .. "zh_tl"] | ||
row.note = args.zh_note | row.note = args[prefix .. "zh_note"] | ||
else | else | ||
row.tl = args[lang .. "_tl"] | row.tl = args[prefix .. lang .. "_tl"] | ||
row.note = args[lang .. "_note"] | row.note = args[prefix .. lang .. "_note"] | ||
end | end | ||
Line 66: | Line 101: | ||
haveTl = true | haveTl = true | ||
end | end | ||
row.tl_rowspan = 1 | |||
row. | |||
tbRows[#tbRows + 1] = row | tbRows[#tbRows + 1] = row | ||
Line 78: | Line 112: | ||
header:tag('th'):wikitext('In-game Name') | header:tag('th'):wikitext('In-game Name') | ||
if haveTl then | if haveTl then | ||
header:tag('th'):wikitext('Literal Meaning') | |||
end | end | ||
for _, row in ipairs(tbRows) do | for _, row in ipairs(tbRows) do | ||
local tr = tb:tag('tr') | local tr = tb:tag('tr') | ||
tr:tag('td'):wikitext(row.name) | tr:tag('td'):tag('b'):wikitext(row.name) | ||
local text = tr:tag('td'):wikitext(row.text) | local text = tr:tag('td'):wikitext(row.text) | ||
Line 91: | Line 123: | ||
text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm) | text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm) | ||
end | end | ||
if haveTl then | if haveTl and not row.tl_skip then | ||
local tl = tr:tag('td'):wikitext(row.tl or "—"):attr(' | local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('rowspan', tostring(row.tl_rowspan)) | ||
if row.note then | if row.note then | ||
tl:wikitext(frame:extensionTag { | tl:wikitext(frame:extensionTag { | ||
name = 'ref', | name = 'ref', | ||
content = row.note, | content = row.note, | ||
args = { name = row.lang, group = '•' } | args = { name = prefix .. row.lang, group = '•' } | ||
}) | }) | ||
end | end | ||
Line 104: | Line 135: | ||
end | end | ||
return tb | return tb | ||
end | end | ||
return p | return p |
Latest revision as of 14:47, 9 July 2024
Some codes from genshin-impact:Template:Other Languages and genshin-impact:Module:Other Languages.
local langOrder = {
-- Retrieved from CMake output, put English first
-- Substitude all _ to -
"en",
"be", "bg", "ca", "cs", "cy", "da", "de", "el", "eo", "es", "et", "eu",
"fa", "fi", "fil", "fr", "ga", "gd", "gl", "hu", "ia", "id", "it", "ja",
"jbo", "jv", "kk", "ko", "ky", "lt", "lv", "lzh", "mi", "mn", "mr", "ms",
"nb", "nl", "nn", "oc", "pl", "pt", "pt-BR", "ro", "ru", "sk", "sl",
"sr-Cyrl", "sr-Latn", "sv", "sw", "tr", "tt", "uk", "vi", "yue",
"zh-CN", "zh-TW" }
local languageData = require('Module:Language/data/ISO 639-1')
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
parentFirst = true,
removeBlanks = false,
wrappers = { 'Template:Other Languages' }
})
return p._main(args, frame)
end
function p._main(args, frame)
local out
if args["1_en"] then
out = mw.html.create('div'):css {
['display'] = 'flex',
['column-gap'] = '15px',
['flex-direction'] = 'row',
['flex-wrap'] = 'wrap'
}
local Y = 1
local y = tostring(Y)
repeat
local entry = out:tag('div')
entry:tag('h3'):wikitext(args[y .. '_header'] or args[y .. '_en'])
entry:node(p.Table(args, frame, (y .. '_')))
Y = Y + 1
y = tostring(Y)
until not args[y .. "_en"]
else
out = p.Table(args, frame, "")
end
return tostring(out) .. frame:extensionTag { name = 'references', args = { group = '•' } }
end
function p.Table(args, frame, prefix)
local tbRows = {}
local stickTl = false
local haveTl = false
-- <lang>: In-game Name
-- <lang_rm: Romanization
-- <lang>_tl: Literal Meaning
for _, lang in ipairs(langOrder) do
if args[prefix .. lang] then
local row = {}
row.lang = lang
row.text = args[prefix .. lang]
if lang == "pt-BR" then
row.name = "Brazilian Portuguese"
elseif lang == "sr-Cyrl" then
row.name = "Serbian<br><small>(Cyrillic)</small>"
stickTl = true
elseif lang == "sr-Latn" then
row.name = "Serbian<br><small>(Latin)</small>"
elseif lang == "zh-CN" then
row.lang = "zh-Hans"
row.name = "Chinese<br><small>(Simplified)</small>"
stickTl = true
elseif lang == "zh-TW" then
row.lang = "zh-Hant"
row.name = "Chinese<br><small>(Traditional)</small>"
elseif lang == "yue" then -- ISO 693-3
row.name = "Yue Chinese"
else
row.name = languageData[lang][1]
end
row.rm = args[prefix .. lang .. "_rm"]
if stickTl and (lang == "sr-Latn" or lang == "zh-TW") then
tbRows[#tbRows].tl_rowspan = 2
row.tl_skip = true
stickTl = false
elseif lang == "sr-Cyrl" or lang == "sr-Latn" then
row.tl = args[prefix .. "sr_tl"]
row.note = args[prefix .. "sr_note"]
elseif lang == "zh-CN" or lang == "zh-TW" then
row.tl = args[prefix .. "zh_tl"]
row.note = args[prefix .. "zh_note"]
else
row.tl = args[prefix .. lang .. "_tl"]
row.note = args[prefix .. lang .. "_note"]
end
if row.tl then
haveTl = true
end
row.tl_rowspan = 1
tbRows[#tbRows + 1] = row
end
end
local tb = mw.html.create('table'):addClass('wikitable'):newline()
local header = tb:tag('tr')
header:tag('th'):wikitext('Language')
header:tag('th'):wikitext('In-game Name')
if haveTl then
header:tag('th'):wikitext('Literal Meaning')
end
for _, row in ipairs(tbRows) do
local tr = tb:tag('tr')
tr:tag('td'):tag('b'):wikitext(row.name)
local text = tr:tag('td'):wikitext(row.text)
if row.rm then
text:wikitext('<br />'):tag('small'):tag('i'):wikitext(row.rm)
end
if haveTl and not row.tl_skip then
local tl = tr:tag('td'):wikitext(row.tl or "—"):attr('rowspan', tostring(row.tl_rowspan))
if row.note then
tl:wikitext(frame:extensionTag {
name = 'ref',
content = row.note,
args = { name = prefix .. row.lang, group = '•' }
})
end
end
end
return tb
end
return p