Module:IPA/category documentation
Appearance
![]() | This module depends on the following other modules: |
Implements Template:IPA language category.
require('strict')
local p = {}
local data = mw.loadData('Module:IPA/data')
local mLang = require('Module:Lang')
function p.main()
local langName = mw.title.getCurrentTitle().text:sub(12, -5)
local fullLangCode, langCode, regionCode, langData, dialectData
for code, lang in pairs(data.langs) do
if lang.name == langName then
fullLangCode = code
langCode = code
langData = lang
break
end
if lang.dialects then
for diaCode, dialect in pairs(lang.dialects) do
if dialect.name == langName then
fullLangCode = code .. '-' .. diaCode
langCode = code
regionCode = diaCode
langData = lang
dialectData = dialect
break
end
end
if fullLangCode then
break
end
end
end
if not fullLangCode then
fullLangCode = mLang._tag_from_name({ langName })
if fullLangCode:sub(1, 5) == '<span' then
fullLangCode = nil
else
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
end
if not fullLangCode then
return string.format('Error: data for "%s" not found', langName)
end
local langLink = dialectData and dialectData.link or
langData and langData.link or
langName:sub(-10) == ' languages' and langName or
langName .. ' language'
local key = dialectData and dialectData.key or langData and langData.key
local langCat = mLang._category_from_tag({ fullLangCode })
if langCat:sub(1, 5) == '<span' then
langCat = nil
end
local parentLangName = regionCode and (
langData.name or mLang._name_from_tag({ langCode })
)
if parentLangName and parentLangName:sub(1, 5) == '<span' then
parentLangName = nil
end
local cat = parentLangName
and 'Pages with ' .. parentLangName .. ' IPA'
or 'Pages with IPA'
local ret = {
string.format(
'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using <code>{{[[Template:IPA|IPA]]|%s|...}}</code>. This category should never be added manually.',
langLink,
langName,
fullLangCode
)
}
if key then
table.insert(ret, string.format(
'By default, the transcriptions are linked to the [[%s]] key. Transcriptions that do not adhere to the conventions of the key must have <code>|generic=yes</code>.',
key
))
end
if langCat then
table.insert(ret, string.format('==See also==\n*[[:%s]]', langCat))
end
table.insert(ret, string.format('[[Category:%s|%s]]', cat, langName))
return table.concat(ret, '\n\n')
end
return p