Module:Peter Bowman/transliteratorPL

There are no reviewed versions of this page, so it may not have been checked for adherence to standards.

Documentation for this module may be created at Module:Peter Bowman/transliteratorPL/doc

local p = {}

local commonTransliteration = {
	["-"] = "-",
	["="] = "=",
	[","] = ",",
	["."] = ".",
	["/"] = "/",
	[";"] = ";",
	["'"] = "'",
	["["] = "[",
	["]"] = "]",
	["\\"] = "\\",
	["`"] = "`",
	["~"] = "~",
	["!"] = "!",
	["@"] = "@",
	["#"] = "#",
	["$"] = "$",
	["%"] = "%",
	["^"] = "^",
	["&"] = "&",
	["*"] = "*",
	["("] = "(",
	[")"] = ")",
	["_"] = "_",
	["+"] = "+",
	["{"] = "{",
	["}"] = "}",
	["|"] = "|",
	[":"] = ":",
	["\""] = "\"",
	["<"] = "<",
	[">"] = ">",
	["?"] = "?" ,
	[" "] = " ",
	["\n"] = "\n"
}

local transliterationPl = {
	["a"] = "а", ["A"] = "А",
	["ą"] = "ѫ", ["Ą"] = "Ѫ",
	["b"] = "б", ["B"] = "Б",
	["c"] = "ц", ["C"] = "Ц",
	["d"] = "д", ["D"] = "Д",
	-- do uzupelnienia
	["ż"] = "ж", ["Ż"] = "Ж",
}

local transliterations = {
	["pl"] = transliterationPl,
}

function p.transliterate( frame )
	local lang = frame.args[ 1 ]
	local text = frame.args[ 2 ]
	local result = {}
	
	local transliteration = transliterations[ lang ]
	
	if transliteration == nil then
		return "Błędny kod języka: " .. lang
	end
	
	for codepoint in mw.ustring.gcodepoint( text ) do
	    local untransliterated = mw.ustring.char( codepoint )
	    local transliterated = commonTransliteration[ untransliterated ]
	    
	    if transliterated == nil then
	        transliterated = transliteration[ untransliterated ]
	    end
	    
	    table.insert( result, ( transliterated == nil )
	    	and "?"
	    	or  transliterated
	    )
	end
	
	return table.concat( result )
end

return p