Diferencia entre revisiones de «Módulo:Otros idiomas»

De Inkipedia
(Importado el módulo Idiomas de Inkipedia inglesa)
 
m (A22PG trasladó la página Módulo:Idiomas a Módulo:Otros idiomas sin dejar una redirección: Nombre cambiado a su correspondiente plantilla)
(Sin diferencias)

Revisión del 08:21 26 feb 2024

La documentación para este módulo puede ser creada en Módulo:Otros idiomas/doc

local p = {}
local gameShortenedModule = require("Module:GameShortened")
local flagModule = require("Module:Bandera")

local function getGameShortened(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: [https://www.w3schools.com/tags/ref_language_codes.asp]
local function handleLanguage(t, args, languageTitle, wikiParameter, flagParameter, htmlLanguageCode)
    if args[wikiParameter] and args[wikiParameter] ~= '' then
        local flag = getFlag(flagParameter)
        if not flag then
            flag = "[[File:Flag.svg|link=]]"
        end

        local htmlLang = htmlLanguageCode or wikiParameter or ""
        local name = args[wikiParameter] or "Unnamed language (" .. wikiParameter .. ")"
        
        local romanized = ""
        if args[wikiParameter .. "R"] and args[wikiParameter .. "R"] ~= "" then
            romanized = "<br/>''" .. args[wikiParameter .. "R"] .. "''"
        end

        local meaning = ""
        if args[wikiParameter .. "M"] and args[wikiParameter .. "M"] ~= "" then
            meaning = args[wikiParameter .. "M"]
        end

        table.insert(t, "|-")
        table.insert(t, "|" .. flag .. "&nbsp;" .. languageTitle .. "|||<span lang=\"" .. htmlLang .. "\">" .. name .. "</span>" .. romanized .. "|||" .. meaning)
    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(getGameShortened(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 "Idioma"))
    table.insert(t, "!" .. (args["column-2"] or "Nombre"))
    table.insert(t, "!" .. (args["column-3"] or "Significado"))

    -- Handle each language
    handleLanguage(t, args, "Japonés", "Japanese", "Jap", "jp", "ja")
    handleLanguage(t, args, "Holandés", "Dutch", "Dut", "nl", "nl")
    handleLanguage(t, args, "Francés", "French", "Fra", "cafr", "fr")
    handleLanguage(t, args, "Francés (NOA)", "French (NOA)", "FraA", "ca", "fr-ca")
    handleLanguage(t, args, "Francés (NOE)", "French (NOE)", "FraE", "fr", "fr-fr")
    handleLanguage(t, args, "Francés", "French", "Fre", "cafr", "fr")
    handleLanguage(t, args, "Francés (NOA)", "French (NOA)", "FreA", "ca", "fr-ca")
    handleLanguage(t, args, "Francés (NOE)", "French (NOE)", "FreE", "fr", "fr-fr")
    handleLanguage(t, args, "Alemán", "German", "Ger", "de", "de")
    handleLanguage(t, args, "Italiano", "Italian", "Ita", "it", "it")
    handleLanguage(t, args, "Ruso", "Russian", "Rus", "ru", "ru")
    handleLanguage(t, args, "Inglés", "English", "Eng", "eng")
    handleLanguage(t, args, "Chino", "Chinese", "Chi", "cn", "zh")
    handleLanguage(t, args, "Chino (Simplificado)", "Chinese (Simplified)", "ChiS", "cn", "zh-Hans")
    handleLanguage(t, args, "Chino (Traditional)", "Chinese (Traditional)", "ChiT", "hk", "zh-Hant")
    handleLanguage(t, args, "Checo", "Czech", "Cze", "cz", "cs")
    handleLanguage(t, args, "Danés", "Danish", "Dan", "da", "da")
    handleLanguage(t, args, "Finlandés", "Finnish", "Fin", "fi", "fi")
    handleLanguage(t, args, "Húngaro", "Hungarian", "Hun", "hu", "hu")
    handleLanguage(t, args, "Coreano", "Korean", "Kor", "kr", "ko")
    handleLanguage(t, args, "Noruego", "Norwegian", "Nor", "no", "no")
    handleLanguage(t, args, "Polaco", "Polish", "Pol", "pl", "pl")
    handleLanguage(t, args, "Portugués", "Portuguese", "Por", "pt", "pt")
    handleLanguage(t, args, "Portugués (NOA)", "Portuguese (NOA)", "PorA", "br", "pt-br")
    handleLanguage(t, args, "Portugués (NOE)", "Portuguese (NOE)", "PorE", "pt", "pt-pt")
    handleLanguage(t, args, "Sueco", "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, "|[[File:Translate logo.svg|border|20px|link=]]&nbsp;Internal|||<span lang=\"\">" .. args["Internal"] .. "</span>|||" .. (args["InternalM"] or ""))
    end

    return table.concat(t, "\n") .. "\n|}"
end

return p