Difference between revisions of "Module:Languages"
Jump to navigation
Jump to search
m |
|||
Line 28: | Line 28: | ||
local header = headers[currLang] or "Language:" | local header = headers[currLang] or "Language:" | ||
local text = "'''[[:" .. title .. "|English]]'''" | local text = "'''[[:" .. title .. "|English]]'''" | ||
+ | local translated = false | ||
for lang, _ in pairs(headers) do | for lang, _ in pairs(headers) do | ||
− | + | local langText = getLangText(frame, title, lang) | |
+ | if langText ~= "" then | ||
+ | text = text ..langText | ||
+ | translated = true | ||
+ | end | ||
end | end | ||
− | + | local nmbox = frame:expandTemplate{title = "nmbox", args = {header = header, text = text}} | |
+ | local categories = "[[Category:Languages pages]]" | ||
+ | if translated then | ||
+ | categories = categories .. "[[Category:Languages pages without translations]]" | ||
+ | end | ||
+ | return nmbox .. categories | ||
end | end | ||
return p | return p |
Revision as of 15:11, 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 = mw.language.fetchLanguageName(lang) local bdi = HtmlBuilder.create("bdi") :attr("lang", lang) :wikitext("", parsedLang, "") return frame:preprocess("")
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" local translated = false for lang, _ in pairs(headers) do local langText = getLangText(frame, title, lang) if langText ~= "" then text = text ..langText translated = true end end local nmbox = frame:expandTemplate{title = "nmbox", args = {header = header, text = text}} local categories = "" if translated then categories = categories .. "" end return nmbox .. categories
end
return p