Module:IPA/category documentation and Module:IPA/category documentation/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
Separate name lookup from text generation |
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.lookup_name( name ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return nil, nil, nil |
|||
⚫ | |||
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 |
||
⚫ | |||
code, lect, parent = p.lookup_name( name ) |
|||
⚫ | |||
lect = lect2 |
|||
⚫ | |||
code = lect.code |
|||
break |
|||
⚫ | |||
⚫ | |||
end |
end |
||
if not code |
if not code then |
||
⚫ | |||
return frame:expandTemplate({ title = 'Hidden category' }) .. string.format('<span class="error" style="font-size: 100%%; font-style: normal;">Error: language code for "%s" not found. Please see [[Template talk:IPA]] for assistance.</span>[[Category:IPA template errors]]', name) |
|||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
lect = lect2 |
|||
⚫ | |||
break |
|||
⚫ | |||
⚫ | |||
⚫ | |||
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' |
|||
if not mw.title.new(link).exists then |
|||
link = mLang._name_from_tag({ code, link = 'yes' }) |
|||
:match('^%[%[([^|%]]+)') |
|||
end |
|||
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 |
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 |
parentName and 'Pages with ' .. parentName .. ' IPA' or |
||
'Pages with IPA' |
|||
) |
) |
||
local sortkey = args.sort or |
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.', |
'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using %s. This category should never be added manually.', |
||
link, |
link, |
||
name, |
name, |
||
code |
code |
||
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code) |
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code) |
||
or '[[Template:IPA]]' |
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, |
|||
isCollective and string.format('The %s are', name) or string.format('%s is', name), |
|||
code and ' (' .. code .. ')' or '' |
code and ' (' .. code .. ')' or '' |
||
)) |
)) |
||
⚫ | |||
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 |