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

(Difference between pages)
Page 1
Page 2
imported>Nardog
uppercase region
 
imported>Nardog
Created page with 'require('strict') local p = {} local data = mw.loadData('Module:IPA/data') local mLang = require('Module:Lang') function p.main(frame) local args = {} for k, v in pairs(frame:getParent().args) do if v ~= '' then args[k] = v end end local langName = mw.title.getCurrentTitle().text:sub(12, -5) local langCode, regionCode, langData, dialectData local fullLangCode = args.code if not fullLangCode then for code, lang in pairs(data.langs) do if...'
 
Line 2: Line 2:


local p = {}
local p = {}
local lects = mw.loadData('Module:IPA/data/export')
local data = mw.loadData('Module:IPA/data')
local mLang = require('Module:Lang')
local mLang = require('Module:Lang')


Line 12: Line 12:
end
end
end
end
local name = mw.title.getCurrentTitle().text:sub(12, -5)
local langName = mw.title.getCurrentTitle().text:sub(12, -5)
local lect, parent
local langCode, regionCode, langData, dialectData
local code = args.code
local fullLangCode = args.code
if not code then
if not fullLangCode then
for _, lect2 in ipairs(lects) do
for code, lang in pairs(data.langs) do
if (lect2.name or lect2.extName) == name then
if lang.name == langName then
lect = lect2
fullLangCode = code
parent = lect.parent
langCode = code
code = lect.code
langData = lang
break
break
end
end
end
if lang.dialects then
end
for diaCode, dialect in pairs(lang.dialects) do
if not code then
if dialect.name == langName then
code = mLang._tag_from_name({ name })
fullLangCode = code .. '-' .. diaCode
if code:find('^<span') then
langCode = code
code = nil
regionCode = diaCode
else
langData = lang
local regionCode = code:match('-(.+)')
dialectData = dialect
if regionCode and regionCode:sub(1, 2) ~= 'x-' then
break
code = code:sub(1, #code - #regionCode) .. regionCode:upper()
end
end
end
for _, lect2 in ipairs(lects) do
if fullLangCode then
if lect2.code == code then
lect = lect2
parent = lect.parent
break
break
end
end
Line 43: Line 40:
end
end
end
end
local isCollective = name:find(' languages$') and true
if not fullLangCode then
local link = lect and (lect.link or lect.generatedLink or lect.extLink) or
fullLangCode = mLang._tag_from_name({ langName })
parent and (parent.link or parent.generatedLink or parent.extLink) or
if fullLangCode:sub(1, 5) == '<span' then
isCollective and name or
fullLangCode = nil
name .. ' language'
end
local key = lect and lect.key or parent and parent.key
end
if fullLangCode then
langCode = fullLangCode:gsub('%-.*', '')
regionCode = fullLangCode:match('%-(.+)')
regionCode = regionCode and regionCode:upper()
langData = data.langs[langCode]
if langData and langData.dialects and regionCode then
dialectData = langData.dialects[regionCode]
end
end
local isCollective = langName:sub(-10) == ' languages'
local langLink = dialectData and dialectData.link or
langData and langData.link or
isCollective and langName or
langName .. ' language'
local key = dialectData and dialectData.key or langData and langData.key
local langCat, langCatCount
local langCat, langCatCount
if code then
if fullLangCode then
langCat = mLang._category_from_tag({ code })
langCat = mLang._category_from_tag({ fullLangCode })
if langCat:find('^<span') then
if langCat:sub(1, 5) == '<span' then
langCat = nil
langCat = nil
else
else
Line 58: Line 70:
end
end
end
end
local parentName = args.parent or
local parentLangName = args.parent or
parent and (parent.name or parent.extName) or
regionCode and langData.name or
code and code:find('-') and mLang._name_from_tag({ code:gsub('%-.*', '') })
mLang._name_from_tag({ langCode })
if parentName == name or
if parentLangName == langName or
parentName and parentName:find('^<span')
parentLangName and parentLangName:sub(1, 5) == '<span'
then
then
parentName = nil
parentLangName = nil
end
end
mw.log(parentLangName)
local cat = args.cat ~= 'no' and (
local cat = args.cat ~= 'no' and (
parentName and 'Pages with ' .. parentName .. ' IPA' or
parentLangName and 'Pages with ' .. parentLangName .. ' IPA' or
'Pages with IPA'
'Pages with IPA'
)
)
local sortkey = args.sort or
local sortkey = args.sort or
name:find('^[ %l]+$') and ' ' .. name or
langName:find('^[ %l]+$') and ' ' .. langName or
name
langName
local ret = {
local ret = {
string.format(
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,
langLink,
name,
langName,
code
fullLangCode
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code)
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', fullLangCode)
or '[[Template:IPA]]'
or '[[Template:IPA]]'
)
)
Line 92: Line 105:
table.insert(ret, string.format(
table.insert(ret, string.format(
'The %s are 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,
langName,
code and ' (' .. code .. ')' or ''
fullLangCode and ' (' .. fullLangCode .. ')'
))
))
end
end
if not code and args.container ~= 'yes' then
if not fullLangCode then
table.insert(ret, string.format(
table.insert(ret, string.format(
'<small>Documentation error: language code for "%s" not found.</small>',
'<small>Documentation error: language code for "%s" not found.</small>',
name
langName
))
))
end
end