Difference between revisions of "Module:Languages"

From Minetest Wiki
Jump to navigation Jump to search
m
m (Fixed for subpages linking to other pages)
Line 20: Line 20:
  
 
function p._languages(frame, args)
 
function p._languages(frame, args)
 +
    local inputTitle = args[1]
 
     local titleObj = mw.title.getCurrentTitle()
 
     local titleObj = mw.title.getCurrentTitle()
 
     local fullTitle = titleObj.text
 
     local fullTitle = titleObj.text
     local title = args[1] or titleObj.nsText .. ":" .. titleObj.baseText
+
     local title = inputTitle or titleObj.nsText .. ":" .. titleObj.baseText
 
     local titleLang = titleObj.subpageText
 
     local titleLang = titleObj.subpageText
 
     if titleLang == fullTitle then
 
     if titleLang == fullTitle then
Line 29: Line 30:
 
     local header = headers[titleLang]
 
     local header = headers[titleLang]
 
     if not header then
 
     if not header then
         title = title .. "/" .. titleLang
+
         title = inputTitle or fullTitle
 
         titleLang = "en"
 
         titleLang = "en"
 
         header = headers[titleLang]
 
         header = headers[titleLang]

Revision as of 19:39, 12 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 inputTitle = args[1]
   local titleObj = mw.title.getCurrentTitle()
   local fullTitle = titleObj.text
   local title = inputTitle or titleObj.nsText .. ":" .. titleObj.baseText
   local titleLang = titleObj.subpageText
   if titleLang == fullTitle then
       titleLang = "en"
   end
   local header = headers[titleLang]
   if not header then
       title = inputTitle or fullTitle
       titleLang = "en"
       header = headers[titleLang]
   end
   local text = "English"
   local translated = false
   for lang, _ in pairs(headers) do
       if lang ~= "en" then
           local langText = getLangText(frame, title, lang)
           if langText ~= "" then
               text = text ..langText
               translated = true
           end
       end
   end
   local nmbox = frame:expandTemplate{
       title = "nmbox",
       args = {
           image = "Languages",
           header = header,
           text = text
       }
   }
   local categories = ""
   if not translated then
       categories = categories .. ""
   end
   return nmbox .. categories

end

return p