Jump to content

Module:IPA/category documentation and Module:IPA/category documentation/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
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 )
for _, lect in ipairs(lects) do
if (lect.name or lect.extName) == name then
return lect.code, lect, lect.parent
end
end

local code = mLang._tag_from_name({ name })
if not code:find('^<span') then
local regionCode = code:match('-(.+)')
if regionCode and regionCode:sub(1, 2) ~= 'x-' then
code = code:sub(1, #code - #regionCode) .. regionCode:upper()
end
for _, lect in ipairs(lects) do
if lect.code == code then
return code, lect, lect.parent
end
end
return code, nil, nil
end

return nil, nil, nil
end


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
code, lect, parent = p.lookup_name( name )
if (lect2.name or lect2.extName) == name then
lect = lect2
parent = lect.parent
code = lect.code
break
end
end
end
end
if not code and args.container ~= 'yes' then
if not code then
code = mLang._tag_from_name({ name })
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)
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
or parent and (parent.link or parent.generatedLink or parent.extLink)
parent and (parent.link or parent.generatedLink or parent.extLink) or
or isCollective and name
isCollective and name or
or name .. ' language'
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
or parent and (parent.name or mLang._name_from_tag({ parent.code, raw = 'yes' }))
parent and (parent.name or parent.extName) or
or code and code:find('-') and mLang._name_from_tag({ code:gsub('%-.*', ''), raw = 'yes' })
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({ title = 'Tracking category' }))
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 or args.collective == 'yes' then
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 ''
))
))
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