Module:Languages

From Dead by Daylight Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Languages/doc

local p = {}
local frame = mw.getCurrentFrame()
local languages = {
	{iso = "ca", name = "Catalan"},
	{iso = "cs", name = "Czech"},
	{iso = "da", name = "Danish"},
	{iso = "el", name = "Greek"},
	{iso = "en", name = "English"},
	{iso = "fi", name = "Finnish"},
	{iso = "fr", name = "French"},
	{iso = "hr", name = "Croatian"},
	{iso = "hu", name = "Hungarian"},
	{iso = "ja", name = "Japanese"},
	{iso = "ko", name = "Korean"},
	{iso = "mn", name = "Mongolian"},
	{iso = "no", name = "Norwegian"},
	{iso = "ro", name = "Romanian"},
	{iso = "ru", name = "Russian"},
	{iso = "sk", name = "Slovak"},
	{iso = "sv", name = "Swedish"},
	{iso = "sw", name = "Swahili"},
	{iso = "th", name = "Thai"},
	{iso = "tr", name = "Turkish"},
	{iso = "uk", name = "Ukrainian"},
	{iso = "vi", name = "Vietnamese"},
	{iso = "za", name = "Zhuang"},
}

function p.resolveLanguageTable()
	local result = ""
	local pageTitle = mw.title.getCurrentTitle().fullText
	--mw.log(pageTitle)
	
	result = result .. "<div class=\"langBox\" style=\"float:right;position:relative;top:-50px\">"
	result = result .. "In other languages:"
	
	--TODO: detect prefix namespace (such as "Module:")
	--mw.log(mw.dumpObject(mw.site.namespaces))
	
	local i = 1
	local langTitle
	local foundLanguages = 0
	while languages[i] do
		langTitle = pageTitle .. "/" .. languages[i].iso
		
		if mw.title.new(langTitle).exists then
			mw.log(langTitle)
			result = result .. " [[File:Language" .. languages[i].name .. ".png|link=" .. langTitle .. "|24px]]" --Temporary text link instead of flags
			foundLanguages = foundLanguages + 1
		end
		i = i + 1
	end
	
	result = result .. "</div><br>"
	
	if foundLanguages > 0 then
		mw.log(result)
		return result
	end
	return nil
end

return p