Gaa na ọdịnaya

Module:Lang-zh

Shí Wikipedia, njikotá édémédé nke onyobulạ
Mmeghari kemgbe 18:49, 8 Eprel 2014 si n'aka JohnBlackburne (ṅkátá | mmetara)
(ndịịche) ← Orübà di kwa nke ichié | Orübà nke ubwa (ndịịche) | Orübà di kwa ohúrù → (ndịịche)

Usage

This is the module for the template {{Lang-zh}}. Its main features are described on that template's documentation page, refer to that for how to use it in articles. This documentation describes some particular features of the module.

The first table in the module lists the articles in which the template will put traditional Chinese first. Add articles to this list in the same fashion (the order doesn't matter) to include them. If you cannot edit the module because its protected use the {{edit template-protected}} template on its talk page to request a change.

Use from other modules

The module can be called directly from another module as well as a template. To do this first load the module

local Zh = require("Module:Lang-zh")._Zh

Then call it as follows, with the arguments in a table

local output = Zh{["c"] = "中国", ["p"] = "zhōngguó"}

Tracking categories


local p = {
    language = require "Module:Language",

    fr = {
        args = {}
    }

}


function p.getParent()
    return p.fr
end


function p.Zh(frame)
-- Get the args. I don't know if there's a preferred way to do it but this works
    local args = {}
     local pframe = frame:getParent()
    for k, v in pframe:argumentPairs() do
        args[k] = v
    end
    local body = "" -- the output string
-- Get all the parameters into vars, or use "" if none is supplied (avoids seperate test for empty strings)
    local c = args["c"] or ""
    local s = args["s"] or ""
    local t = args["t"] or ""
    local hp = args["p"] or args["hp"] or ""
    local tp = args["tp"] or ""
    local w = args["w"] or ""
    local j = args["j"] or ""
    local cy = args["cy"] or ""
    local poj = args["poj"] or ""
    local zhu = args["zhu"] or ""
    local l = args["l"] or ""
    local no = args["links"] == "no"
    local t1 = args["first"] == "t"

    if (c > "" or (s > "" and s == t)) then -- if simplified and traditional the same they are merged into Chinese.
        c = c or s
        p.fr.args[1], p.fr.args[2] = "zh", c
        c = p.language.lang(p)
        if (no) then -- handle "links=no"
            body = body .. "Chinese: " .. c .. "; "
        else 
            body = body .. "[[Chinese language|Chinese]]: " .. c .. "; "
        end
    end
-- temporaries, used for reordering
    local sOut, tOut = "", ""

    if (s ~= t) then -- if they are the same should under Chinese
        if (s  > "") then
            p.fr.args[1], p.fr.args[2]  = "zh-Hans", s
            s = p.language.lang(p)
            if (t  > "") then -- only display full name if traditional also appears
                name = "simplified Chinese"
            else 
                name = "Chinese"
            end
            if (no) then -- handle "links=no"
                sOut = name .. ": " .. s .. "; "
            else
                sOut = "[[Simplified Chinese character|" .. name .."]]: " .. s .. "; "
            end
        end
        if (t  > "") then
            p.fr.args[1], p.fr.args[2]  = "zh-Hant", t
            t = p.language.lang(p)
            if (s  > "") then -- only display full name if simplified also appears
                name = "traditional Chinese"
            else 
                name = "Chinese"
            end
            if (no) then -- handle "links=no"
                tOut = name .. ":" .. t .. "; "
            else
                tOut = "[[Traditional Chinese character|" .. name .."]]: " .. t .. "; "
            end
        end
        if (t1) then -- order based on "first=t"
            body = body .. tOut .. sOut
        else
            body = body .. sOut .. tOut
        end
    end

    sOut = ""
    tOut = ""
    if (hp > "") then
            if (tp  > "") then -- only display full name if Tongyo pinyin also appears
                name = "Hanyu Pinyin"
            else 
                name = "pinyin"
            end
        if (no) then -- handle "links=no"
            sOut = name .. ": ''" .. hp .. "''; "
        else
            sOut = "[[pinyin|" .. name .. "]]: ''" .. hp .. "''; "
        end
    end
    if (tp  > "") then
        if (no) then -- handle "links=no"
            tOut = "Tongyong Pinyin: " .. tp .. "; "
        else
            tOut = "[[Tongyong Pinyin]]: " .. tp .. "; "
        end
    end
    if (t1) then -- order based on "first=t"
        body = body .. tOut .. sOut
    else
        body = body .. sOut .. tOut
    end

    if (w  > "") then
        if (no) then -- handle "links=no"
            body = body .. "Wade-Giles: " .. w .. "; "
        else
            body = body .. "[[Wade-Giles]]: " .. w .. "; "
        end
    end
    if (j  > "") then
        if (no) then -- handle "links=no"
            body = body .. "Jyutping: " .. j .. "; "
        else
            body = body .. "[[Jyutping]]: " .. j .. "; "
        end
    end
    if (cy  > "") then
        if (no) then -- handle "links=no"
            body = body .. "Yale: " .. cy .. "; "
        else
            body = body .. "[[Yale romanization|Yale]]: " .. cy .. "; "
        end
    end
    if (poj  > "") then
        if (no) then -- handle "links=no"
            body = body .. "Pe̍h-ōe-jī: " ..poj .. "; " 
        else
            body = body .. "[[Pe̍h-ōe-jī]]: " ..poj .. "; "
        end
    end
    if (zhu  > "") then
        if (no) then -- handle "links=no"
            body = body .. "Zhuyin Fuhao: " .. zhu .. "; "
        else
            body = body .. "[[Bopomofo|Zhuyin Fuhao]]: " .. zhu .. "; "
        end
    end
    if (l  > "") then
        body = body .. "literally: \"" .. l .. "\"; "
    end
    if (body > "") then -- check for empty string
        return string.sub(body, 1, -3) -- chop off final semicolon and space
    else --no named parameters; see if there's an unnamed first parameter
        c = pframe.args[1] or ""
        if (c > "") then -- if there is treat it as Chinese
            if (no) then -- handle "links=no"
                return "Chinese: " .. c
            else 
                return "[[Chinese language|Chinese]]: " .. c
            end
        end
        return body
    end
end

return p