Difference between revisions of "Module:Languages"
Jump to navigation
Jump to search
m |
m |
||
Line 7: | Line 7: | ||
function p.languages(frame) | function p.languages(frame) | ||
local args = getArgs(frame, {inherited = true}) | local args = getArgs(frame, {inherited = true}) | ||
− | return p._languages(args) | + | return p._languages(frame, args) |
end | end | ||
− | local function getLangText(title, lang) | + | local function getLangText(frame, title, lang) |
title = title .. "/" .. lang | title = title .. "/" .. lang | ||
− | local parsedLang = " | + | local parsedLang = frame:callParserFunction("#language", lang) |
local bdi = HtmlBuilder.create("bdi") | local bdi = HtmlBuilder.create("bdi") | ||
:attr("lang", lang) | :attr("lang", lang) | ||
:wikitext("[[:", title, "|", parsedLang, "]]") | :wikitext("[[:", title, "|", parsedLang, "]]") | ||
− | return " | + | return frame:callParserFunction("#ifexist", title, " • " .. tostring(bdi)) |
end | end | ||
− | function p._languages(args) | + | function p._languages(frame, args) |
local titleObj = mw.title.getCurrentTitle() | local titleObj = mw.title.getCurrentTitle() | ||
local title = args[1] or titleObj.nsText .. ":" .. titleObj.baseText | local title = args[1] or titleObj.nsText .. ":" .. titleObj.baseText | ||
Line 31: | Line 31: | ||
text = text .. getLangText(title, lang) | text = text .. getLangText(title, lang) | ||
end | end | ||
− | return | + | return frame:expandTemplate{title = 'nmbox', args = {header = header, text = text}} |
end | end | ||
return p | return p |
Revision as of 08:02, 10 April 2017
local p = {}
local HtmlBuilder = require("Module:HtmlBuilder") local getArgs = require("Module:Arguments").getArgs local headers = mw.loadData('Module:Languages/headers')
function p.languages(frame)
local args = getArgs(frame, {inherited = true}) return p._languages(frame, args)
end
local function getLangText(frame, title, lang)
title = title .. "/" .. lang local parsedLang = frame:callParserFunction("#language", lang) local bdi = HtmlBuilder.create("bdi") :attr("lang", lang) :wikitext("", parsedLang, "") return frame:callParserFunction("#ifexist", title, " • " .. tostring(bdi))
end
function p._languages(frame, args)
local titleObj = mw.title.getCurrentTitle() local title = args[1] or titleObj.nsText .. ":" .. titleObj.baseText local currLang = titleObj.subpageText if currLang == titleObj.text then currLang = "en" end local header = headers[currLang] or "Language:" local text = "English" for lang, _ in pairs(headers) do text = text .. getLangText(title, lang) end return frame:expandTemplate{title = 'nmbox', args = {header = header, text = text}}
end
return p