Модул: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:Zh")._Zh
Then call it as follows, with the arguments in a table
local output = Zh{["c"] = "中国", ["p"] = "zhōngguó"}
Modules used
[уреди извор]Tracking categories
[уреди извор]
require('strict')
local p = {}
-- articles in which traditional Chinese preceeds simplified Chinese
local t1st = {
["Инцидент 228"] = true,
["Кинески календар"] = true,
["Липо центар (Хонгконг)"] = true,
["Република Кина"] = true,
["Република Кина на Летњим олимпијским играма 1928."] = true,
["Република Кина (1912—1949)"] = true,
["Тајван (острво)"] = true,
["Тајван (покрајина Републике Кине)"] = true,
["Веј Бојанг"] = true,
}
-- the labels for each part
local labels = {
["к"] = "кин",
["у"] = "упрош",
["т"] = "трад",
["п"] = "пин",
["тп"] = "тп",
["вџ"] = "вџ",
["ј"] = "ј",
["кј"] = "кј",
["сл"] = "сл",
["пој"] = "ПОЈ",
["б"] = "б",
["д"] = "досл.",
["прев"] = "прев.",
}
-- article titles for wikilinks for each part
local wlinks = {
["к"] = "кинески језик",
["у"] = "поједностављено кинеско писмо",
["т"] = "традиционално кинеско писмо",
["п"] = "пинјин",
["тп"] = "тонгјонг пинјин",
["вџ"] = "Вејд-Џајлс",
["ј"] = "јитпинг",
["кј"] = "јејлова романизација кантонског",
["сл"] = "Сидни Лауова романизација",
["пој"] = "певеџи",
["б"] = "бопомофо",
["д"] = "дослован превод",
["прев"] = "превод",
}
-- for those parts which are to be treated as languages their ISO code
local ISOlang = {
["к"] = "zh",
["т"] = "zh-Hant",
["у"] = "zh-Hans",
["п"] = "zh-Latn-pinyin",
["тп"] = "zh-Latn",
["вџ"] = "zh-Latn-wadegile",
["ј"] = "yue-Latn-jyutping",
["кј"] = "yue-Latn",
["сл"] = "yue-Latn",
["пој"] = "nan-Latn",
["б"] = "zh-Bopo",
}
local italic = {
["п"] = true,
["тп"] = true,
["вџ"] = true,
["ј"] = true,
["кј"] = true,
["сл"] = true,
["пој"] = true,
}
local superscript = {
["вџ"] = true,
["сл"] = true,
}
-- Categories for different kinds of Chinese text
local cats = {
["к"] = "[[Категорија:Чланци који садрже текст на језику — кинески]]",
["у"] = "[[Категорија:Чланци који садрже текст на језику — упрошћени кинески]]",
["т"] = "[[Категорија:Чланци који садрже текст на језику — традиционални кинески]]",
}
function p.Zh(frame)
-- load arguments module to simplify handling of args
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return p._Zh(args)
end
function p._Zh(args)
if args["link"] then args["links"] = args["link"]; end
if args["label"] then args["labels"] = args["label"]; end
local uselinks = args["links"] ~= "no" -- whether to add links
local uselabels = args["labels"] ~= "no" -- whether to have labels
local capfirst = args["scase"] ~= nil
local out = nil -- which term to put before the brackets
local usebrackets = 0 -- whether to have bracketed terms
local numargs = 0
if args["out"] then
out = args["out"]
usebrackets = 1
end
local t1 = false -- whether traditional Chinese characters go first
local j1 = false -- whether Cantonese Romanisations go first
local testChar
if (args["first"]) then
for testChar in mw.ustring.gmatch(args["first"], "%a+") do
if (testChar == "т") then
t1 = true
end
if (testChar == "ј") then
j1 = true
end
end
end
if (t1 == false) then
local title = mw.title.getCurrentTitle()
t1 = t1st[title.text] == true
end
-- based on setting/preference specify order
local orderlist = {"к", "у", "т", "п", "тп", "вџ", "ј", "кј", "сл", "пој", "б", "д", "прев"}
if (t1) then
orderlist[2] = "т"
orderlist[3] = "у"
end
if (j1) then
orderlist[4] = "ј"
orderlist[5] = "кј"
orderlist[6] = "сл"
orderlist[7] = "п"
orderlist[8] = "тп"
orderlist[9] = "вџ"
end
-- rename rules. Rules to change parameters and labels based on other parameters
if args["хп"] then
-- hp an alias for p ([ханју] пинјин)
args["п"] = args["хп"]
end
if args["тп"] then
-- if also Tongyu pinyin use full name for Hanyu pinyin
labels["п"] = "ханју пинјин"
end
if (args["у"] and args["у"] == args["т"]) then
-- Treat simplified + traditional as Chinese if they're the same
args["к"] = args["у"]
args["у"] = nil
args["т"] = nil
if out == "у" or out == "т" then
out = "к"
end
elseif (not (args["у"] and args["т"])) then
-- use short label if only one of simplified and traditional
labels["у"] = labels["к"]
labels["т"] = labels["к"]
end
if out then
for i, v in ipairs (orderlist) do -- shift `out` to the beginning of the order list
if v == out then
table.remove(orderlist, i)
table.insert(orderlist, 1, v)
break
end
end
end
if (out == "к" and args["у"]) then usebrackets = 2; end
local body = "" -- the output string
local params -- for creating HTML spans
local label -- the label, i.e. the bit preceeding the supplied text
local val -- the supplied text
-- go through all possible fields in loop, adding them to the output
for i, part in ipairs(orderlist) do
if (args[part]) then
numargs = numargs + 1
-- build label
label = ""
if (uselabels) then
label = labels[part]
if (capfirst) then
label = mw.language.getContentLanguage():ucfirst(label)
capfirst = false
end
if (uselinks and part ~= "д" and part ~= "прев") then
label = "[[" .. wlinks[part] .. "|" .. label .. "]]"
end
if (part == "д" or part == "прев") then
label = "<abbr title=\"" .. wlinks[part] .. "\"><small>" .. label .. "</small></abbr>"
else
label = label .. ":"
end
label = label .. " "
end
-- build value
val = args[part]
if (cats[part]) and mw.title.getCurrentTitle().namespace == 0 then
-- if has associated category AND current page in article namespace, add category
val = cats[part] .. val
end
if (ISOlang[part]) then
-- add span for language if needed
params = {["lang"] = ISOlang[part]}
val = mw.text.tag({name="span",attrs=params, content=val})
elseif (part == "д") then
local terms = ""
-- put individual, potentially comma-separated glosses in single-quotes
for term in val:gmatch("[^;,]+") do
term = string.gsub(term, "^([ \"']*)(.*)([ \"']*)$", "%2")
terms = terms .. "'" .. term .. "', "
end
val = string.sub(terms, 1, -3)
elseif (part == "прев") then
-- put translations in double quotes
val = """ .. val .. """
end
if (italic[part]) then
-- italicise
val = "<i>" .. val .. "</i>"
end
if string.match(val, "</?sup>") then val = val.."[[Category:Pages using template Zh with sup tags]]" end
if (superscript[part]) then
-- superscript
val = val:gsub("(%d)", "<sup>%1</sup>"):gsub("(%d)</sup>%*<sup>(%d)", "%1*%2"):gsub("<sup><sup>([%d%*]+)</sup></sup>", "<sup>%1</sup>")
end
-- add both to body
if numargs == usebrackets then
-- opening bracket after the `out` term
body = body .. label .. val .. " ("
else
body = body .. label .. val .. "; "
end
end
end
if (body > "") then -- check for empty string
body = string.sub(body, 1, -3) -- chop off final semicolon and space
if out and numargs > usebrackets then
-- closing bracket after the rest of the terms
body = body .. ")"
end
return body
else --no named parameters; see if there's a first parameter, ignoring its name
if (args[1]) then
-- if there is treat it as Chinese
label = ""
if (uselabels) then
label = labels["к"]
if (uselinks) then
label = "[[" .. wlinks["к"] .. "|" .. label .. "]]"
end
label = label .. ": "
end
-- default to show links and labels as no options given
if mw.title.getCurrentTitle().namespace == 0 then
-- if current page in article namespace
val = cats["к"] .. args[1]
else
val = args[1]
end
params = {["lang"] = ISOlang["к"]}
val = mw.text.tag({name="span",attrs=params, content=val})
return label .. val
end
return ""
end
end
return p