Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Ru-rm

From The Petit Planet Wiki

Documentation for this module may be created at Module:Ru-rm/doc

local p = {}

local mapping = {
	["А"]='A',    ["а"]='a',
	["Е"]='E',    ["е"]='e',
	["Ё"]='Yo',   ["ё"]='yo',
	["И"]='I',    ["и"]='i',
	["О"]='O',    ["о"]='o',
	["У"]='U',    ["у"]='u',
	["Ы"]='Y',    ["ы"]='y',
	["Э"]='E',    ["э"]='e',
	["Ю"]='Yu',   ["ю"]='yu',
	["Я"]='Ya',   ["я"]='ya',
	["Й"]='Y',    ["й"]='y',
	["Б"]='B',    ["б"]='b',
	["В"]='V',    ["в"]='v',
	["Г"]='G',    ["г"]='g',
	["Д"]='D',    ["д"]='d',
	["Ж"]='Zh',   ["ж"]='zh',
	["З"]='Z',    ["з"]='z',
	["К"]='K',    ["к"]='k',
	["Л"]='L',    ["л"]='l',
	["М"]='M',    ["м"]='m',
	["Н"]='N',    ["н"]='n',
	["П"]='P',    ["п"]='p',
	["Р"]='R',    ["р"]='r',
	["С"]='S',    ["с"]='s',
	["Т"]='T',    ["т"]='t',
	["Ф"]='F',    ["ф"]='f',
	["Х"]='Kh',   ["х"]='kh',
	["Ц"]='Ts',   ["ц"]='ts',
	["Ч"]='Ch',   ["ч"]='ch',
	["Ш"]='Sh',   ["ш"]='sh',
	["Щ"]='Shch', ["щ"]='shch',
	["Ъ"]='"',    ["ъ"]='"',
	["Ь"]="'",    ["ь"]="'",
	["«"]='"',    ["»"]='"',
}

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		parentFirst = true,
		wrapper = { 'Template:Ru-rm' }
	})
	return p._main(args, frame)
end

function p._main(args, frame)
	local text = require('Module:tt').CleanTT(args[1])
	
	text = mw.ustring.gsub(text, '<ref[^>]*(>[^<]*<\/ref>|\/>)', '')            --remove references
	text = mw.ustring.gsub(text, '^([Ее])', '¤%1')                              --mark Е/е with ¤ at the beginning of the text
	text = mw.ustring.gsub(text, '([^ЁёА-я¤])([Ее])', '%1¤%2')                  --mark Е/е with ¤ at the beginning of a word
	text = mw.ustring.gsub(text, '([АаЕеЁёИиОоУуЫыЭэЮюЯяЪъЬь])([Ее])', '%1¤%2') --mark Е/е with ¤ after vowels and modifier letters
	text = mw.ustring.gsub(text, '¤[Ее]', {['¤Е']='Йе', ['¤е']='йе'})           --replace Е/е marked with ¤ with Йе/йе which will be romanized as Ye/ye
	text = mw.ustring.gsub(text, '.', mapping)                                  --romanize everything

    return text
end

return p