Module:WorkersVoices: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| Line 15: | Line 8: | ||
driver_transport = "Driver / transport", general_expat_life = "General expat life", | driver_transport = "Driver / transport", general_expat_life = "General expat life", | ||
study_work_settlement = "Study, work & settlement", | study_work_settlement = "Study, work & settlement", | ||
other = "Other | other = "Other", | ||
} | } | ||
local | local SENTIMENT_ICONS = { | ||
positive = "Positive", mixed = "Mixed", negative = "Negative", | positive = "🟢 Positive", mixed = "🟡 Mixed", negative = "🔴 Negative", | ||
} | } | ||
| Line 25: | Line 18: | ||
if not s then return "" end | if not s then return "" end | ||
return (s:gsub("|", "|"):gsub("%[", "["):gsub("%]", "]")) | return (s:gsub("|", "|"):gsub("%[", "["):gsub("%]", "]")) | ||
end | |||
local function tlen(t) | |||
local n = 0 | |||
for _ in ipairs(t) do n = n + 1 end | |||
return n | |||
end | end | ||
| Line 30: | Line 29: | ||
if g == "man" then return "Man" end | if g == "man" then return "Man" end | ||
if g == "woman" then return "Woman" end | if g == "woman" then return "Woman" end | ||
return " | return "''Not specified''" | ||
end | |||
local function sectorLabel(s) | |||
if not s or s == "unclear" then return "''Not yet confirmed''" end | |||
return SECTOR_LABELS[s] or wikiEscape(s) | |||
end | |||
local function sentimentLabel(s) | |||
return SENTIMENT_ICONS[s] or "Unknown" | |||
end | |||
local function warningLabel(video) | |||
if not (video.contentWarning and video.contentWarning.flag) then | |||
return "—" | |||
end | |||
local label = video.contentWarning.label or "" | |||
if label:find("automated discovery") then | |||
return "🔍 ''Pending review''" | |||
end | |||
return "⚠️ '''" .. wikiEscape(label) .. "'''" | |||
end | end | ||
| Line 43: | Line 62: | ||
data = mw.text.jsonDecode(content) | data = mw.text.jsonDecode(content) | ||
end | end | ||
local rows = {} | local rows = {} | ||
| Line 52: | Line 68: | ||
for _, region in ipairs(data.regions) do | for _, region in ipairs(data.regions) do | ||
for _, country in ipairs(region.countries) do | for _, country in ipairs(region.countries) do | ||
if tlen(country.videos) == 0 then | |||
table.insert(noVideoLines, | table.insert(noVideoLines, | ||
"* " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name)) | "* " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name)) | ||
else | else | ||
for _, video in ipairs(country.videos) do | for _, video in ipairs(country.videos) do | ||
local resource = "—" | local resource = "—" | ||
if video.verifiedResource and video.verifiedResource.url then | if video.verifiedResource and video.verifiedResource.url then | ||
| Line 77: | Line 88: | ||
"| " .. wikiEscape(region.name), | "| " .. wikiEscape(region.name), | ||
"| " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name), | "| " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name), | ||
"| " .. ( | "| " .. sectorLabel(video.sector), | ||
"| " .. genderLabel(video.gender), | "| " .. genderLabel(video.gender), | ||
"| " .. ( | "| " .. sentimentLabel(video.sentiment), | ||
"| " .. wikiEscape(video.addedDate), | "| " .. wikiEscape(video.addedDate), | ||
"| " .. sourceLink, | "| " .. sourceLink, | ||
"| " .. | "| " .. warningLabel(video), | ||
"| " .. note, | "| " .. note, | ||
"| " .. resource, | "| " .. resource, | ||
Revision as of 14:34, 27 September 2026
Documentation for this module may be created at Module:WorkersVoices/doc
local p = {}
local SECTOR_LABELS = {
construction = "Construction", domestic_work = "Domestic work",
hospitality = "Hospitality", healthcare = "Healthcare",
skilled_it = "Skilled / IT", agriculture = "Agriculture",
general_worker_life = "General worker life", employment_advice = "Employment advice",
driver_transport = "Driver / transport", general_expat_life = "General expat life",
study_work_settlement = "Study, work & settlement",
other = "Other",
}
local SENTIMENT_ICONS = {
positive = "🟢 Positive", mixed = "🟡 Mixed", negative = "🔴 Negative",
}
local function wikiEscape(s)
if not s then return "" end
return (s:gsub("|", "|"):gsub("%[", "["):gsub("%]", "]"))
end
local function tlen(t)
local n = 0
for _ in ipairs(t) do n = n + 1 end
return n
end
local function genderLabel(g)
if g == "man" then return "Man" end
if g == "woman" then return "Woman" end
return "''Not specified''"
end
local function sectorLabel(s)
if not s or s == "unclear" then return "''Not yet confirmed''" end
return SECTOR_LABELS[s] or wikiEscape(s)
end
local function sentimentLabel(s)
return SENTIMENT_ICONS[s] or "Unknown"
end
local function warningLabel(video)
if not (video.contentWarning and video.contentWarning.flag) then
return "—"
end
local label = video.contentWarning.label or ""
if label:find("automated discovery") then
return "🔍 ''Pending review''"
end
return "⚠️ '''" .. wikiEscape(label) .. "'''"
end
function p.main(frame)
local dataPageTitle = frame.args[1] or "Data:WorkersVoices.json"
local data
if mw.loadJsonData then
data = mw.loadJsonData(dataPageTitle)
else
local content = mw.title.new(dataPageTitle):getContent()
data = mw.text.jsonDecode(content)
end
local rows = {}
local noVideoLines = {}
for _, region in ipairs(data.regions) do
for _, country in ipairs(region.countries) do
if tlen(country.videos) == 0 then
table.insert(noVideoLines,
"* " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name))
else
for _, video in ipairs(country.videos) do
local resource = "—"
if video.verifiedResource and video.verifiedResource.url then
resource = "[" .. video.verifiedResource.url .. " " ..
wikiEscape(video.verifiedResource.label) .. "]"
end
local note = video.curatorNote and video.curatorNote ~= ""
and ("''" .. wikiEscape(video.curatorNote) .. "''") or "—"
local sourceLink = "[" .. video.sourceUrl .. " Source]"
table.insert(rows, table.concat({
"|-",
"| " .. wikiEscape(region.name),
"| " .. wikiEscape(country.flag) .. " " .. wikiEscape(country.name),
"| " .. sectorLabel(video.sector),
"| " .. genderLabel(video.gender),
"| " .. sentimentLabel(video.sentiment),
"| " .. wikiEscape(video.addedDate),
"| " .. sourceLink,
"| " .. warningLabel(video),
"| " .. note,
"| " .. resource,
}, "\n"))
end
end
end
end
local tableWikitext = table.concat({
'{| class="wikitable sortable"',
"! Region !! Country !! Sector !! Gender !! Sentiment !! Added !! Source !! Content warning !! Why we picked this !! Verified resource",
table.concat(rows, "\n"),
"|}",
}, "\n")
local out = { tableWikitext }
if #noVideoLines > 0 then
table.insert(out, "\n'''No account currently featured for:'''\n")
table.insert(out, table.concat(noVideoLines, "\n"))
end
return table.concat(out, "\n")
end
return p