Module:yux-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate Southern Yukaghir language text. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:yux-translit/testcases.

Functions[edit]

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

local u = mw.ustring.char

local MACRON    = u(0x0304)
local DOTABOVE  = u(0x0307)
local DOTBELOW  = u(0x0323)

local str_gsub, ugsub = string.gsub, mw.ustring.gsub
local UTF8char = '[\1-\127\194-\244][\128-\191]*'

local export = {}

local tab = {
	["А"]='A', ["а"]='a', ["Б"]='B', ["б"]='b', ["В"]='W', ["в"]='w', 
	["Г"]='G', ["г"]='g', ["Ҕ"]='H', ["ҕ"]='h',	["Д"]='D', ["д"]='d', 
	["Ж"]='Ž', ["ж"]='ž', ["И"]='I', ["и"]='i', ["Й"]='J', ["й"]='j',
	["К"]='K', ["к"]='k', ["Л"]='L', ["л"]='l', ["М"]='M', ["м"]='m',
	["Н"]='N', ["н"]='n', ["Ҥ"]='Ŋ', ["ҥ"]='ŋ',	["О"]='O', ["о"]='o',
	["Ө"]='Ø', ["ө"]='ø', ["П"]='P', ["п"]='p', ["Р"]='R', ["р"]='r', 
	["Т"]='T', ["т"]='t', ["У"]='U', ["у"]='u', ["Ф"]='F', ["ф"]='f', 
	["Х"]='Q', ["х"]='q', ["Ч"]='Č', ["ч"]='č',	["Ш"]='Š', ["ш"]='š', 
	["Э"]='E', ["э"]='e',
	
	-- non-native letters
	 ["Е"]='Je', ["е"]='je', 
	 ["Ё"]='Jo', ["ё"]='jo',
	 ["З"]='Z', ["з"]='z', 
	 ["Ц"]='C', ["ц"]='c',  
	 ["Щ"]='Ś', ["щ"]='ś', 
	 ["Ы"]='Y', ["ы"]='y',
	 ["Ю"]='Ju', ["ю"]='ju',
	 ["Я"]='Ja', ["я"]='ja',
	 ['Ъ']="ʺ", ['ъ']="ʺ", 
	 ["Ь"]='ʹ', ["ь"]='ʹ',
	 ["С"]='S', ["с"]='s'
}

local other = {
	{ 'Аа', 'Ā' },
	{ 'аа', 'ā' },
	{ 'Ээ', 'Ē' },
	{ 'ээ', 'ē' },
	{ 'Ии', 'Ī' },
	{ 'ии', 'ī' },
	{ 'Оо', 'Ō' },
	{ 'оо', 'ō' },
	{ 'Уу', 'Ū' },
	{ 'уу', 'ū' },
	{ 'Өө', 'Ø̄'},
	{ 'өө', 'ø̄'},
	{ 'Оу', 'Ow'},
	{ 'оу', 'ow'},
}
 
function export.tr(text, lang, sc)
	for i, replacement in ipairs(other) do
		text = str_gsub(text, unpack(replacement))
	end
 
    return (str_gsub(text, UTF8char, tab))
end

return export