Module:IPA/category documentation and Module:IPA/category documentation/sandbox: Difference between pages
(Difference between pages)
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 | 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 | local langName = mw.title.getCurrentTitle().text:sub(12, -5) | ||
local | local langCode, regionCode, langData, dialectData | ||
local | local fullLangCode = args.code | ||
if not | if not fullLangCode then | ||
for | for code, lang in pairs(data.langs) do | ||
if | if lang.name == langName then | ||
fullLangCode = code | |||
langCode = code | |||
langData = lang | |||
break | break | ||
end | 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 | |||
if | |||
break | break | ||
end | end | ||
Line 43: | Line 40: | ||
end | end | ||
end | end | ||
local isCollective = | if not fullLangCode then | ||
local | fullLangCode = mLang._tag_from_name({ langName }) | ||
if fullLangCode:sub(1, 5) == '<span' then | |||
isCollective and | fullLangCode = nil | ||
end | |||
local 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 | if fullLangCode then | ||
langCat = mLang._category_from_tag({ | langCat = mLang._category_from_tag({ fullLangCode }) | ||
if langCat: | if langCat:sub(1, 5) == '<span' then | ||
langCat = nil | langCat = nil | ||
else | else | ||
Line 58: | Line 70: | ||
end | end | ||
end | end | ||
local | local parentLangName = args.parent or | ||
regionCode and langData.name or | |||
mLang._name_from_tag({ langCode }) | |||
if | if parentLangName == langName or | ||
parentLangName and parentLangName:sub(1, 5) == '<span' | |||
then | then | ||
parentLangName = nil | |||
end | end | ||
mw.log(parentLangName) | |||
local cat = args.cat ~= 'no' and ( | local cat = args.cat ~= 'no' and ( | ||
parentLangName and 'Pages with ' .. parentLangName .. ' IPA' or | |||
'Pages with IPA' | 'Pages with IPA' | ||
) | ) | ||
local sortkey = args.sort or | local sortkey = args.sort or | ||
langName:find('^[ %l]+$') and ' ' .. langName or | |||
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.', | ||
langLink, | |||
langName, | |||
fullLangCode | |||
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</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.', | ||
langName, | |||
fullLangCode and ' (' .. fullLangCode .. ')' | |||
)) | )) | ||
end | end | ||
if not | 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>', | ||
langName | |||
)) | )) | ||
end | end |