Module:Languages/config

local p = {}

-- Map all known language codes to their autonyms per MediaWiki, then fix up a -- few codes and names that are incorrect in MediaWiki for historical reasons. local languageNamesByCode = mw.language.fetchLanguageNames languageNamesByCode.gcf = "kréyòl gwadloupéyen" -- Guadeloupean Creole French languageNamesByCode["sr-cyrl"] = languageNamesByCode["sr-ec"] languageNamesByCode["sr-latn"] = languageNamesByCode["sr-el"]

--- A table mapping language codes to their autonyms. Every language code in --- languageCodes must have a pair in this table, but this table has many pairs --- that go unused in languageCodes. p.languageNamesByCode = languageNamesByCode

--- A table of ISO 639 language codes for the languages used on this wiki, --- sorted by autonym. A language code may be included only if there is at least --- one content page in the language that has the code in its title (either as a --- namespace or a pseudonamespace). Empty categories and redirects don’t count. p.languageCodes = { -- After modifying this table, rerun p.languageCodesSortedByName in the -- debug console below and paste the re-sorted results here. This ensures -- that the codes are sorted by language name. "af", "ast", "az", "id", "ms", "bs", "br", "ca", "cs", "da", "de", "et", "en", "es", "eo", "eu", "fr", "fy", "gl", "hr", "ia", "is", "it", "ht", "gcf", "ku", "lv", "lb", "lt", "hu", "nl", "no", "nn", "oc", "pl", "pt", "ro", "sq", "sk", "sl", "sr-latn", "fi", "sv", "tl", "vi", "tr", "diq", "el", "be", "bg", "mk", "mn", "ru", "sr", "uk", "hy", "he", "ar", "fa", "ps", "ne", "bn", "ta", "ml", "si", "th", "my", "ka", "ko", "tzm", "zh-hans", "zh-hant", "ja", "yue", }

--- A table of language codes for languages that are only nominally used on this --- wiki. A language code is included in this table if there is at least one --- non-redirect page in the language, such as a category or template. If there --- is a content page in the language, place the code in languageCodes instead. p.minorLanguageCodes = { "ab", "am", "an", "as", "av", "ay", "ba", "bm", "bo", "co", "cy", "dv", "ext", "ga", "gd", "gsw", "gu", "ha", "hi", "ie", "ig", "jv", "kk", "km", "kn", "ky", "la", "li", "lo", "mg", "min", "mr", "mt", "nan", "nds", "nds-nl", "om", "or", "pa", "sa", "sd", "so", "su", "sw", "te", "tg", "tk", "ug", "ur", "uz", "vec", "wa", "wo", "wuu", "xh", "yi", "yo", "za", "zu", "zh", }

--- A table mapping deprecated language codes to their preferred replacements. --- Deprecated language codes should not be used on new pages, but a few content --- pages remain under these pseudonamespaces for now. p.deprecatedLanguageCodes = { ["pt-br"] = "pt", ["ro-md"] = "ro", ["zh-tw"] = "zh-hant", }

--- A table mapping language codes to their content namespaces. For historical --- reasons, several early languages got dedicated content namespaces, but most --- languages rely on pseudonamespaces in the main content namespace. Apart from --- pseudonamespaces, the main content namespace is assumed to be in English. p.namespacesByLanguage = { ["de"] = "DE", ["en"] = "", ["es"] = "ES", ["fr"] = "FR", ["it"] = "IT", ["ja"] = "JA", ["nl"] = "NL", ["ru"] = "RU", }

--- A table mapping certain language codes to the names of the categories --- tracking missing translations in those languages. This table only includes --- languages that have dedicated namespaces. p.unavailablePageCategoryNames = { ["de"] = "Pages unavailable in German", ["en"] = "Pages unavailable in English", ["es"] = "Pages unavailable in Spanish", ["fr"] = "Pages unavailable in French", ["it"] = "Pages unavailable in Italian", ["ja"] = "Pages unavailable in Japanese", ["nl"] = "Pages unavailable in Dutch", ["ru"] = "Pages unavailable in Russian", }

if mw.title.getCurrentTitle.fullText == "Module:Languages/config" then --- Logs a table of language codes sorted by autonym. This function is only --- available in the debug console, because NFD normalization uses a lot of --- memory. p.languageCodesSortedByName = function local siteLanguage = mw.getContentLanguage local codes = {} local sortingKeys = {} for i, code in ipairs(p.languageCodes) do			table.insert(codes, code) local foldedName = siteLanguage:caseFold(languageNamesByCode[code]) -- Fold diacritics by isolating and deleting combining characters. sortingKeys[code] = mw.ustring.gsub(mw.ustring.toNFD(foldedName),				"[^%a%p%s]+", "") end table.sort(codes, function (a, b)			return sortingKeys[a] < sortingKeys[b]		end) mw.log((table.concat(codes, " "):gsub("(%S+)", "\"%1\","))) end end

return p