Jump to content

Module:Editnotice load/config loader

From Wikipedia, the free encyclopedia
local hasI18n, i18n = pcall(mw.loadData, "Module:Editnotice load/i18n")
local hasCfg, loadCfg = pcall(mw.loadData, "Module:Editnotice load/config")
if not hasI18n then i18n = {} end
if not hasCfg then loadCfg = {} end
local currLang = mw.language.getContentLanguage().code
local function fetch(message, lang, fallback)
	return i18n[lang][message] or i18n[fallback][message] or error("Internationalization and configuration files for [[Module:Editnotice load]] is missing!")
end

--[=[===========================================================================
LOAD THE CONFIGURATION FILE. WE WILL BE ASSUMING THE I18N IS PRESENT, IF IT IS 
NOT, THEN IT WILL THROW AN ERROR.

OPTIONAL CONFIGURATION WILL BE SET TO nil OR EMPTY STRING.
=============================================================================]=]
local cfg = {
	pseudo_ns_name = loadCfg.pseudo_ns_name or fetch("pseudo_ns_name", currLang, "en"),
	editnotice_classes = loadCfg.editnotice_classes or "",
	editnotice_types = {
		protection = loadCfg.editnotice_types.protection or fetch("editnotice_types_protection", currLang, "en"),
		protection_id = loadCfg.editnotice_types.protection_id or fetch("editnotice_types_protection_id", currLang, "en"),
		title = loadCfg.editnotice_types.title or fetch("editnotice_types_title", currLang, "en"),
		page = loadCfg.editnotice_types.page or fetch("editnotice_types_page", currLang, "en"),
		group = loadCfg.editnotice_types.group or fetch("editnotice_types_group", currLang, "en"),
		category = loadCfg.editnotice_types.category or fetch("editnotice_types_category", currLang, "en"),
		namespace = loadCfg.editnotice_types.namespace or fetch("editnotice_types_namespace", currLang, "en")
	},
	user_editnotice = loadCfg.user_editnotice or nil,
	links = loadCfg.links or fetch("links", currLang, "en"),
	editnotice_names = {
		protection = loadCfg.editnotice_names.protection or fetch("editnotice_names_protection", currLang, "en"),
		protection_id = loadCfg.editnotice_names.protection_id or fetch("editnotice_names_protection_id", currLang, "en"),
		title = loadCfg.editnotice_names.title or fetch("editnotice_names_title", currLang, "en"),
		page = loadCfg.editnotice_names.page or fetch("editnotice_names_page", currLang, "en"),
		group = loadCfg.editnotice_names.group or fetch("editnotice_names_group", currLang, "en"),
		category = loadCfg.editnotice_names.category or fetch("editnotice_names_category", currLang, "en"),
		namespace = loadCfg.editnotice_names.namespace or fetch("editnotice_names_namespace", currLang, "en")
	},
	noEditnoticePage = loadCfg.noEditnoticePage or fetch("noEditnoticePage", currLang, "en"),
	mainspace = loadCfg.mainspace or fetch("mainspace", currLang, "en"),
	templateStyles = loadCfg.templateStyles or ""
}

return cfg