Module:uk-translit

Hello, you have come here looking for the meaning of the word Module:uk-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:uk-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:uk-translit in singular and plural. Everything you need to know about the word Module:uk-translit you have here. The definition of the word Module:uk-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:uk-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate Ukrainian language text per WT:UK TR. 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:uk-translit/testcases.

Functions

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 export = {}

local m_str_utils = require("Module:string utilities")
 
local rsubn = m_str_utils.gsub

-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
	local retval = rsubn(term, foo, bar)
	return retval
end

local regular_tt = {
	='A', ='a', ='B', ='b', ='V', ='v', ='H', ='h', 
	='G', ='g', ='D', ='d', ='E', ='e', ='Je', ='je', 
	='Ž', ='ž', ='Z', ='z', ='Y', ='y', ='I', ='i', 
	='Ji', ='ji', ='J', ='j', ='K', ='k', ='L', ='l', 
	='M', ='m', ='N', ='n', ='O', ='o', ='P', ='p', 
	='R', ='r', ='S', ='s', ='T', ='t', ='U', ='u', 
	='F', ='f', ='X', ='x', ='C', ='c', ='Č', ='č', 
	='Š', ='š', ='Šč', ='šč', ='ʹ', ='ʹ', ='Ju', ='ju', 
	='Ja', ='ja', 
	-- right single quotation mark, modifier letter apostrophe → modifier letter double prime
	='ʺ', = 'ʺ', 
	-- Ukrainian style quotes
	='“', ='”',
	-- Special char used in ]
	='ᵣ',
}

-- These need to be separated from the `regular_tt` so they don't interfere with reverse translit.
local obsolete_tt = {
	-- obsolete letters, pre-refom
	='Ë', ='ë', ='ʺ', ='ʺ', ='Y', ='y', ='I', ='i', 
	='È', ='è', ='J', ='j',
	-- obsolete letters, Middle Ukrainian
	='Je', ='je', ='ʺ', ='ʺ', ='Y', ='y', ='I', ='i', 
	='Ja', ='ja', ='Ja', ='ja', ='U', ='u', ='Ju', ='ju', 
	='Ks', ='ks', ='Ps', ='ps', ='F', ='f', ='I', ='i', 
	='O', ='o', 
}

local AC = m_str_utils.char(0x0301) -- acute =  ́
local acute_decomposer = {
	 = "a" .. AC,
	 = "e" .. AC,
	 = "i" .. AC,
	 = "o" .. AC,
	 = "u" .. AC,
	 = "y" .. AC,
	 = "A" .. AC,
	 = "E" .. AC,
	 = "I" .. AC,
	 = "O" .. AC,
	 = "U" .. AC,
	 = "Y" .. AC,
}


function export.tr(text, lang, sc)--translit any words or phrases
	-- Remove word-final hard sign, either utterance-finally or followed by
	-- a non-letter character such as space, comma, period, hyphen, etc.
	text = rsub(text, "$", "")
	text = rsub(text, "()", "%1")

	text = rsub(text, "'+", {  = 'ʺ' }) -- neutral apostrophe
	text = rsub(text, '.', regular_tt)
	text = rsub(text, '.', obsolete_tt)

	return text
end


function export.reverse_tr(text)--reverse-translit any words or phrases
	local reverse_tt = {}
	for k, v in pairs(regular_tt) do
		reverse_tt = k
	end
	reverse_tt = "'"
	reverse_tt = "ь"
	reverse_tt = "и"
	reverse_tt = "И"
	text = rsub(text, '.', acute_decomposer)
	text = rsub(text, '', reverse_tt)
	text = rsub(text, 'č', reverse_tt)
	text = rsub(text, '.', reverse_tt)
	return text
end

return export