User:Harimaron/Sandbox/Module:Localized name

From Inkipedia, the Splatoon wiki

local p = {} local gameShortenedModule = require("Module:Game shortened") local flagModule = require("Module:Flag")

local function getGame shortened(game, default)

   return gameShortenedModule.getGame(game, default)

end

local function getFlag(country)

   return flagModule.getFlag(country, "20x20")

end

-- Function to handle a single language entry in the table -- t: the table to append -- args: the frame args which includes the Meaning and Romanized values if applicable -- languageTitle: the Title Case description of the language -- wikiParameter: the base wiki parameter (without M and R) for the language we are handling -- flagParameter: the two letter lower-case code for this language -- htmlLanguageCode: the language code used in HTML for this language. Reference: [1] local function handleLanguage(t, args, languageTitle, wikiParameter, flagParameter, htmlLanguageCode) local function getOneName(args, wikiParameter)

       local name = args[wikiParameter] or "Unnamed language (" .. wikiParameter .. ")"
       
       local romanized = ""
       if args[wikiParameter .. "R"] and args[wikiParameter .. "R"] ~= "" then
           romanized = "
" .. args[wikiParameter .. "R"] .. "" end
       local meaning = ""
       if args[wikiParameter .. "M"] and args[wikiParameter .. "M"] ~= "" then
           meaning = args[wikiParameter .. "M"]
       end
       
       return {
       	name=name,
       	romanized=romanized,
       	meaning=meaning,
       }

end

local names = {}

if args[wikiParameter] and args[wikiParameter] ~= then table.insert(names, getOneName(args, wikiParameter)) end for i=1,9 do if args[wikiParameter .. i] and args[wikiParameter .. i] ~= then table.insert(names, getOneName(args, wikiParameter .. i)) end end

   if table.getn(names) > 0 then
       local flag = getFlag(flagParameter)
       if not flag then
           flag = ""
       end
       local htmlLang = htmlLanguageCode or wikiParameter or ""

for i,v in ipairs(names) do table.insert(t, "|-") local row = "" if i == 1 then if table.getn(names) > 1 then row = "|rowspan=\"" .. table.getn(names) .. "\"" end row = row .. "|" .. flag .. " " .. languageTitle .. "||" end row = row .. "|" .. v.name .. "" .. v.romanized .. "|||" .. v.meaning table.insert(t, row)

       end
   end

end

function p.main(frame)

   local args = frame:getParent().args
   return p.localizedName(args)

end

function p.localizedName(args)

   local colorClass = "generic"
   if args["color"] and args["color"] ~=  then
       colorClass = mw.ustring.lower(getGame shortened(args["color"], "generic")) or "generic"
   end
   local t = {}
   mw.logObject(colorClass)
   table.insert(t, '{| class="wikitable sitecolor-' .. colorClass .. '" style="min-width: 25%;')
   if args["title"] then
       table.insert(t, "|+" .. args.title)
   end
   table.insert(t, "!" .. (args["column-1"] or "Language"))
   table.insert(t, "!" .. (args["column-2"] or "Name"))
   table.insert(t, "!" .. (args["column-3"] or "Meaning"))
   -- Handle each language
   handleLanguage(t, args, "Japanese", "Jap", "jp", "ja")
   handleLanguage(t, args, "Dutch", "Dut", "nl", "nl")
   handleLanguage(t, args, "French", "Fra", "cafr", "fr")
   handleLanguage(t, args, "French (NOA)", "FraA", "ca", "fr-ca")
   handleLanguage(t, args, "French (NOE)", "FraE", "fr", "fr-fr")
   handleLanguage(t, args, "French", "Fre", "cafr", "fr")
   handleLanguage(t, args, "French (NOA)", "FreA", "ca", "fr-ca")
   handleLanguage(t, args, "French (NOE)", "FreE", "fr", "fr-fr")
   handleLanguage(t, args, "German", "Ger", "de", "de")
   handleLanguage(t, args, "Italian", "Ita", "it", "it")
   handleLanguage(t, args, "Russian", "Rus", "ru", "ru")
   handleLanguage(t, args, "Spanish", "Spa", "esmx", "es")
   handleLanguage(t, args, "Spanish (NOA)", "SpaA", "mx", "es-mx")
   handleLanguage(t, args, "Spanish (NOE)", "SpaE", "es", "es-es")
   handleLanguage(t, args, "Chinese", "Chi", "cn", "zh")
   handleLanguage(t, args, "Chinese (Simplified)", "ChiS", "cn", "zh-Hans")
   handleLanguage(t, args, "Chinese (Traditional)", "ChiT", "hk", "zh-Hant")
   handleLanguage(t, args, "Czech", "Cze", "cz", "cs")
   handleLanguage(t, args, "Danish", "Dan", "da", "da")
   handleLanguage(t, args, "Finnish", "Fin", "fi", "fi")
   handleLanguage(t, args, "Hungarian", "Hun", "hu", "hu")
   handleLanguage(t, args, "Korean", "Kor", "kr", "ko")
   handleLanguage(t, args, "Norwegian", "Nor", "no", "no")
   handleLanguage(t, args, "Polish", "Pol", "pl", "pl")
   handleLanguage(t, args, "Portuguese", "Por", "pt", "pt")
   handleLanguage(t, args, "Portuguese (NOA)", "PorA", "br", "pt-br")
   handleLanguage(t, args, "Portuguese (NOE)", "PorE", "pt", "pt-pt")
   handleLanguage(t, args, "Swedish", "Swe", "se", "sv")
   -- Internal is a bit different because there's no code or flag
   if args["Internal"] and args["Internal"] ~=  then
       table.insert(t, "|-")
       table.insert(t, "| Internal|||" .. args["Internal"] .. "|||" .. (args["InternalM"] or ""))
   end
   return table.concat(t, "\n") .. "\n|}"

end

return p