Module:IPA/category documentation and Module:IPA/category documentation/sandbox: Difference between pages
(Difference between pages)
imported>Anomie Separate name lookup from text generation |
imported>Gonnym No edit summary |
||
| Line 4: | Line 4: | ||
local lects = mw.loadData('Module:IPA/data/export') | local lects = mw.loadData('Module:IPA/data/export') | ||
local mLang = require('Module:Lang') | local mLang = require('Module:Lang') | ||
function p.main(frame) | function p.main(frame) | ||
| Line 40: | Line 16: | ||
local code = args.code | local code = args.code | ||
if not code then | if not code then | ||
for _, lect2 in ipairs(lects) do | |||
if (lect2.name or lect2.extName) == name then | |||
lect = lect2 | |||
parent = lect.parent | |||
code = lect.code | |||
break | |||
end | |||
end | |||
end | end | ||
if not code | if not code then | ||
code = mLang._tag_from_name({ name }) | |||
if code:find('^<span') then | |||
code = nil | |||
else | |||
local regionCode = code:match('-(.+)') | |||
if regionCode and regionCode:sub(1, 2) ~= 'x-' then | |||
code = code:sub(1, #code - #regionCode) .. regionCode:upper() | |||
end | |||
for _, lect2 in ipairs(lects) do | |||
if lect2.code == code then | |||
lect = lect2 | |||
parent = lect.parent | |||
break | |||
end | |||
end | |||
end | |||
end | end | ||
local isCollective = name:find(' languages$') and true | local isCollective = name:find(' languages$') and true | ||
local link = lect and (lect.link or lect.generatedLink or lect.extLink) | local link = lect and (lect.link or lect.generatedLink or lect.extLink) or | ||
parent and (parent.link or parent.generatedLink or parent.extLink) or | |||
isCollective and name or | |||
name .. ' language' | |||
local key = lect and lect.key or parent and parent.key | local key = lect and lect.key or parent and parent.key | ||
local langCat, langCatCount | local langCat, langCatCount | ||
| Line 64: | Line 58: | ||
end | end | ||
end | end | ||
local parentName = args.parent | local parentName = args.parent or | ||
parent and (parent.name or parent.extName) or | |||
code and code:find('-') and mLang._name_from_tag({ code:gsub('%-.*', '') }) | |||
if parentName == name or parentName and parentName:find('^<span') then | if parentName == name or | ||
parentName and parentName:find('^<span') | |||
then | |||
parentName = nil | parentName = nil | ||
end | end | ||
local cat = args.cat ~= 'no' and ( | local cat = args.cat ~= 'no' and ( | ||
parentName and 'Pages with ' .. parentName .. ' IPA' or 'Pages with IPA' | parentName and 'Pages with ' .. parentName .. ' IPA' or | ||
'Pages with IPA' | |||
) | ) | ||
local sortkey = args.sort or name:find('^[ %l]+$') and ' ' .. name or name | local sortkey = args.sort or | ||
name:find('^[ %l]+$') and ' ' .. name or | |||
name | |||
local ret = {} | local ret = {} | ||
table.insert(ret, frame:expandTemplate | table.insert(ret, frame:expandTemplate{title = 'Tracking category'}) | ||
table.insert(ret, string.format( | table.insert(ret, | ||
string.format( | |||
'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using %s. This category should never be added manually.', | |||
link, | |||
name, | |||
code | |||
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code) | |||
or '[[Template:IPA]]' | |||
) | |||
) | |||
if key then | if key then | ||
table.insert(ret, string.format( | table.insert(ret, string.format( | ||
| Line 90: | Line 91: | ||
)) | )) | ||
end | end | ||
if isCollective | if isCollective then | ||
table.insert(ret, string.format( | table.insert(ret, string.format( | ||
'%s a language collective. Please replace the code%s with those of more specific languages where possible.', | 'The %s are a language collective. Please replace the code%s with those of more specific languages where possible.', | ||
name, | |||
code and ' (' .. code .. ')' or '' | code and ' (' .. code .. ')' or '' | ||
)) | )) | ||
end | |||
if not code and args.container ~= 'yes' then | |||
local layout = {} | |||
local error_message = string.format('language code for "%s" not found. Please see [[Template talk:IPA]] for assistance.', name) | |||
table.insert(layout, string.format('<span style="font-size: 100%%; font-style: normal;" class="error">Error: %s</span>', error_message)) | |||
table.insert(layout, "[[Category:IPA template errors]]") | |||
return table.concat(layout) | |||
end | end | ||
if args.content then | if args.content then | ||