Module:TranslatedCat
Jump to navigation
Jump to search
Documentation for this module may be created at Module:TranslatedCat/doc
local exports = {}
-- Custom primary languages for sorting purposes
local customPrimary = {
-- Inuktitut (Canadian syllabics) -> Inuktitut
['ike-cans'] = 'iu',
-- Inuktitut (Latin) -> Inuktitut
['ike-latn'] = 'iu',
-- Tajik (Cyrillic) -> [no primary]
['tg-cyrl'] = '',
}
-- For the provided language code's primary subtag (the portion before hyphen),
-- this will return the name of its [[Category:Translated scripts]] sub-category
function exports.getPrimaryCat(frame)
local langCode = frame.args[1]
local contentLang = mw.language.getContentLanguage()
local primaryCode = customPrimary[langCode] or langCode:match('^%a+')
local primaryName = mw.language.fetchLanguageName(primaryCode)
-- The primary language name is used as parent category when the
-- language code ('pt-BR') and its primary code ('pt') differ,
-- and when the primary is a recognised language itself (some
-- primary codes are only for language collectives, e.g. 'roa')
if langCode ~= primaryCode and primaryName ~= '' then
return '/' .. contentLang:ucfirst(primaryName)
end
-- No parent category
return ''
end
return exports