Module:inc-ash/dial/sandbox

local m_translit = require("Module:translit-redirect")

local sub = mw.ustring.sub

local export = {}

local variety_list = {

"Central", "East", "Northwest", "West", "South"

}

local variety_colour = {

["Central"]		= "FAF5F0",

["East"]		= "F0F5FA",

["Northwest"]	= "F0FAF3",

["West"]		= "FAF0F6",

["South"]		= "FAF9F0",

}

local special_note = {

-- none yet

}

function export.main(frame)

local args = frame:getParent.args

local pagename = mw.title.getCurrentTitle.text

local target_page = args[1] or pagename

local resource_page = "Module:inc-ash/dial/data/" .. target_page

local variety_data = require("Module:inc-ash/dial/data")

if mw.title.new(resource_page).exists then

m_syndata = require(resource_page).list

else

return frame:expandTemplate{ title = "Template:inc-ash-dial/uncreated", args = { target_page } }

end

local template = {

["Central"]		= {},

["East"]		= {},

["Northwest"]	= {},

["West"]		= {},

["South"]		= {},

}

main_title = mw.ustring.gsub((target_page == pagename and pagename or  .. target_page .. ), "[0-9%-]", "")

text = [=[

{| class="wikitable mw-collapsible mw-collapsed" style="margin:0; text-align:center;"

|-

! style="background:#FCFFFC; width:40em" colspan=3 | Dialectal forms of  ]=] ..

main_title .. '  (“' .. m_syndata["meaning"] .. '”) ' .. [=[

|-

! style="background:#E8ECFA" | Variety

! style="background:#E8ECFA" | Location

! style="background:#E8ECFA" | Forms]=] .. [=[

[]=] ..

tostring(mw.uri.fullUrl("Module:inc-ash/dial/data/" .. target_page, { ["action"] = "edit" })) ..

' edit] '

m_syndata["meaning"] = nil

if m_syndata["note"] then

note = m_syndata["note"]

m_syndata["note"] = nil

end

local categories = ""

for location, synonym_set in pairs(m_syndata) do

-- check if location is in alias list and use the proper one if so

if variety_data['aliases'][location] ~= nil then location = variety_data['aliases'][location] end

local sc = "Brah"

if location == "Shahbazgarhi" or location == "Mansehra" then

sc = "Khar"

end

if synonym_set[1] ~= "" then

local formatted_synonyms = {}

for i, synonym in ipairs(synonym_set) do

local synonym_decomp = mw.text.split(synonym, ":")

table.insert(formatted_synonyms,

"%1%2") .. "" ..

(synonym_decomp[2] and '  .. synonym_decomp[2] .. ' ..

(i < #synonym_set and ' ' or "") or ""))

end

local location_data = variety_data[location]

local location_name = mw.ustring.gsub(location_data.english or location, "(%(.*%))", " %1 ")

local location_link = location_data.link or location_name

table.insert(template[location_data.group],

{ location_data.order, location_name, location_link, formatted_synonyms })

end

end

local attested = {}

for _, variety in ipairs(variety_list) do

local sc = "Brah"

if variety == "Northwest" then

sc = "Khar"

end

local colour = variety_colour[variety]

if #template[variety] > 0 then

table.sort(template[variety], function(first, second) return first[1] < second[1] end)

for i, point_data in ipairs(template[variety]) do

local result = {}

for _, word in ipairs(point_data[4]) do

if mw.ustring.gsub(sub(word, 3, -3), "%]%].+$", "") == pagename then

table.insert(attested, {point_data[3], point_data[2]})

categories = categories .. ""

end

local tr = mw.ustring.gsub(m_translit.tr(sub(word, 3, -3), "inc-ash", sc), "%]%].+$", "")

local add = ' ' .. word .. " (" .. tr

if point_data["ts"] ~= nil then add = add .. " /" .. point_data["ts"] .. "/" end

add = add .. ") "

table.insert(result, add)

end

text = text .. "\n|-"

if i == 1 then

text = text .. "\n!rowspan=" .. #template[variety] .. (special_note[variety] and " colspan=2" or "") ..

' style="background:#' .. colour .. '"| ' .. (special_note[variety] or variety)

end

text = text .. ((point_data[2] and not special_note[variety]) and ('\n|style="background:#' .. colour .. '"| ' ..

 .. point_data[2] .. ) or '') ..

'\n|style="background:#' .. colour .. "'| " ..

table.concat(result, ", ")

end

end

end

if note and note ~= "" then

text = text .. '\n|-\n! style="background:#FFF7FB; padding-top:5px; padding-bottom: 5px" | ' ..

" Note \n| colspan=2| ''" .. note .. "'' "

end

local res = "Attested at "

table.sort(attested, function(first, second) return first[2] < second[2] end)

for i, dialect in ipairs(attested) do

if i == #attested and i ~= 1 then

res = res .. " and "

elseif i ~= 1 then

res = res .. ", "

end

res = res ..  .. dialect[2] .. 

end

return res .. '.\n' .. text .. '\n|}' .. categories

end

return export