Content deleted Content added
improve main language detection |
use same data for both tables |
||
Line 1:
require('strict')
local p = {}
local data = mw.title.getCurrentTitle().subpageText == 'sandbox'
and mw.loadData('Module:IPA/data/sandbox')
or mw.loadData('Module:IPA/data')
local lects = mw.loadData('Module:IPA/data/export')
local function
if #notes > 0 then
cell:wikitext(
string.format(' <small>(%s)</small>', table.concat(notes, '; '))
)
end
end
Line 136 ⟶ 32:
:tag('th'):wikitext('Key'):done()
:done()
local langRow, langCells, dialectCount
for i, lect in ipairs(lects) do
local row
local cells = {}
if lect.parent then
dialectCount = dialectCount + 1
if dialectCount == 1 then
row = langRow
else
row = t:tag('tr')
for _, cell in ipairs(langCells) do
cell:attr('rowspan', dialectCount)
end
end
else
row = t:tag('tr')
langRow = row
langCells = cells
dialectCount = 0
end
for _ = 1, 4 do
table.insert(cells, row:tag('td'))
end
if not lect.parent and (not lects[i + 1] or not lects[i + 1].diaCode) then
for _ = 1, 4 do
row:tag('td'):css('background', '#ececec')
end
end
cells[1]:wikitext('<code>' .. (lect.diaCode or lect.code) .. '</code>')
if lect.aliases then
addNotes(cells[1], {
string.format(
'also <code>%s</code>',
table.concat(lect.aliases, '</code>, <code>')
)
})
end
do
local notes = {}
if lect.name then
if lect.name == lect.extName then
table.insert(notes, 'redundant')
elseif lect.extName then
table.insert(notes, string.format('overrides "%s"', lect.extName))
end
end
if lect.text then
table.insert(notes, string.format('label: "%s"', lect.text))
end
cells[2]:wikitext(lect.name or lect.extName)
addNotes(cells[2], notes)
end
do
local notes = {}
local intLink = lect.link or lect.generatedLink
if intLink then
if intLink == lect.extLink then
table.insert(notes, 'redundant')
elseif lect.extLink then
local note = string.format('overrides [[%s]]', lect.extLink)
local intTitle = mw.title.new(intLink)
intTitle = intTitle.redirectTarget or intTitle
local extTitle = mw.title.new(lect.extLink)
extTitle = extTitle.redirectTarget or extTitle
if intTitle ~= extTitle then
note = note .. ', a different article'
end
table.insert(notes, note)
end
end
local s = intLink or lect.extLink
s = lect.generatedLink and '([[' .. s .. ']])' or '[[' .. s .. ']]'
cells[3]:wikitext(s)
addNotes(cells[3], notes)
end
cells[4]:wikitext(
lect.key and '[[' .. lect.key .. ']]' or
'([[' .. (lect.parent and lect.parent.key or data.defaultKey) .. ']])'
)
end
return tostring(t)
end
function p.keys()
local
:tag('caption'):addClass('nowrap'):wikitext('Languages with dedicated keys'):done()
:tag('tr')
Line 172 ⟶ 123:
:tag('th'):wikitext('Code'):done()
:done()
local byKey, keys = {}, {}
for _, lect in ipairs(
if key then
if not byKey[key] then
byKey[key] = {}
table.insert(keys, key)
end
table.insert(byKey[key], {
code = lect.code,
name = lect.name or lect.extName,
link = lect.link or lect.generatedLink or lect.extLink,
})
end
end
table.sort(keys)
for _, key in ipairs(keys) do
local row =
local keyCell = row:tag('td'):wikitext('[[' .. key .. ']]')
local
local lang
if #
keyCell:attr('rowspan', #
table.sort(
end)
local keyName = mw.ustring.gsub(key, '^[^/]*/', '')
for _, lect in ipairs(
if lect.name == keyName then
lang = lect
Line 204 ⟶ 157:
end
if not lang then
for _, lect in ipairs(
if lect.name:find(' languages$') then
lang = lect
break
Line 212 ⟶ 165:
end
if not lang then
for _, lect in ipairs(
if not lect.code:find('-') then
lang = lect
Line 221 ⟶ 174:
end
if not lang then
lang =
end
local nameCell = row:tag('td'):wikitext(
Line 228 ⟶ 181:
local nameRowspan = 1
row:tag('td'):wikitext('<code>' .. lang.code .. '</code>')
for i, lect in ipairs(
if lect ~= lang then
local subRow =
local prev = i == 1 and lang or
if prev.name == lect.name then
nameRowspan = nameRowspan + 1
Line 245 ⟶ 198:
end
end
return tostring(
end
|