Module:zh-see: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
ex. search for insource:/cat=n}}/ |
No edit summary |
||
Line 13: | Line 13: | ||
['o'] = 'an obsolete', ['obsolete'] = 'an obsolete', |
['o'] = 'an obsolete', ['obsolete'] = 'an obsolete', |
||
['v'] = 'a variant', ['var'] = 'a variant', ['variant'] = 'a variant', |
['v'] = 'a variant', ['var'] = 'a variant', ['variant'] = 'a variant', |
||
['av'] = 'an ancient variant', |
|||
['sv'] = 'the simplified and variant traditional', |
['sv'] = 'the simplified and variant traditional', |
||
['all'] = 'a simplified, obsolete or variant', |
['all'] = 'a simplified, obsolete or variant', |
Revision as of 23:00, 6 August 2016
- The following documentation is located at Module:zh-see/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
Soft redirection module for non-lemma Chinese pages. See {{zh-see}}
for more.
local export = {}
local sub = mw.ustring.sub
local match = mw.ustring.match
local function link(text, make_link)
return '<span lang="zh" class="Hani">' .. (make_link and ('[[' .. text .. '#Chinese|' .. text .. ']]') or text) .. '</span>'
end
function export.show(frame)
local non_lemma_type = {
['s'] = 'the simplified', ['simp'] = 'the simplified', ['simplified'] = 'the simplified',
['a'] = 'an ancient', ['ancient'] = 'an ancient',
['o'] = 'an obsolete', ['obsolete'] = 'an obsolete',
['v'] = 'a variant', ['var'] = 'a variant', ['variant'] = 'a variant',
['av'] = 'an ancient variant',
['sv'] = 'the simplified and variant traditional',
['all'] = 'a simplified, obsolete or variant',
}
local args = frame:getParent().args
local title = args[1]
local curr_title = mw.title.getCurrentTitle().subpageText
local content = mw.title.new(title):getContent()
local simp = args["simp"] or false
local non_lemma_abbrev = args[2] or ""
if non_lemma_abbrev == "" and mw.title.new(title).exists then
content = mw.title.new(title):getContent()
template = mw.ustring.match(content, "{{zh%-forms[^}]*}}") or false
if template then
for forms_template in mw.ustring.gmatch(content, "{{zh%-forms[^}]*}}") do
if match(forms_template, curr_title) then
if match(forms_template, "s[0-9]*=" .. curr_title) then
non_lemma_abbrev = non_lemma_abbrev .. "s"
end
if match(forms_template, "t[0-9]*=" .. curr_title) then
non_lemma_abbrev = non_lemma_abbrev .. "v"
end
break
end
end
end
end
local non_lemma_cat = non_lemma_type[non_lemma_abbrev ~= "" and non_lemma_abbrev or 's'] or 'the simplified'
local note = (mw.title.new(title) or {}).exists and "" or '[[Category:Chinese terms with uncreated forms]]'
local box =
'{| class="wikitable' .. (match(non_lemma_cat, 'simplified') and ' mw-collapsible mw-collapsed' or '') ..
'" style="border:1px solid #797979; margin-left: 1px; text-align:left; min-width:70%"' ..
'\n|-\n| style="background-color: #eeeeee; padding-left: 0.5em" | \'\'\'For pronunciation and definitions of \'\'\'' .. link(mw.ustring.gsub(curr_title, '(.)', '[[%1]]'), false) ..
'\'\'\' – see <span style="font-size:120%">' .. link(title, true) .. '</span>' .. (args[3] and (' ("' .. args[3] .. '")') or '') .. '.\'\'\'' ..
'<br>(This ' .. (mw.ustring.len(title) == 1 and 'character' or 'term' ) .. ', ' .. link(curr_title) .. ', is ' .. ' \'\'' .. non_lemma_cat .. '\'\' form of ' .. link(title) .. '' ..
(simp and
('<small>: ' .. link(sub(simp, 1, 1), true) .. ' → ' .. link(sub(simp, 2, 2), true) .. '</small>')
or
'') .. '.)' ..
(match(non_lemma_cat, 'simplified') and [=[
|-
| class="mw-collapsible-content" style="background-color: #F5DEB3; font-size: smaller" | <b>Notes:</b>
* [[w:Simplified Chinese|Simplified Chinese]] is mainly used in Mainland China and Singapore.
* [[w:Traditional Chinese|Traditional Chinese]] is mainly used in Hong Kong, Macau and Taiwan.]=] or '') ..
'\n|}' .. note
local cat = { "variant", "simplified", "obsolete" }
local m_cat = require("Module:zh-cat")
categories = ''
for _, word in ipairs(cat) do
if match(non_lemma_cat, word) then
categories = categories .. m_cat.categorize(word)
end
end
if content then
for match_result in mw.ustring.gmatch(content, '{{zh%-pron.+\n%|cat%=[^\n]+\n?}}') do
local function find_pron(variety)
return sub(match(match_result, variety .. '=[^|}]+') or '', mw.ustring.len(variety) + 2, -1)
end
categories = categories .. mw.getCurrentFrame():expandTemplate{
title = "Template:zh-pron",
args = {
['m'] = find_pron('m'),
['c'] = find_pron('c'),
['g'] = find_pron('g'),
['h'] = find_pron('h'),
['j'] = find_pron('j'),
['md'] = find_pron('md'),
['mn'] = find_pron('mn'),
['mn-t'] = find_pron('mn-t'),
['w'] = find_pron('w'),
['x'] = find_pron('x'),
['cat'] = find_pron('cat'),
['only_cat'] = 'yes',
}
}
end
end
return box .. categories
end
return export