Module:ro-translit

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

This module will transliterate Romanian 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:ro-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 concat = table.concat
local explode = require("Module:string utilities").explode_utf8
local insert = table.insert
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local uupper = string.uupper

-- Note: ё, ъ and щ only exist in borrowings.
local letters = {
	 = "a",  = "b",  = "v",  = "g",  = "d",  = "e",  = "io",  = "j",  = "gi",  = "z",  = "i",  = "i",  = "c",  = "l",  = "m",  = "n",  = "o",  = "p",  = "r",  = "s",  = "t",  = "u",  = "f",  = "h",  = "ț",  = "ci",  = "ș",  = "șc",  = "ă",  = "î",  = "i",  = "ă",  = "iu",  = "ia"
}

local vowel = {
	 = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true,  = true
}

local i_vowel_prev = {
	 = true,  = true,  = true
}

local ei_vowel_nxt = {
	 = true,  = true,  = true,  = true,  = true,  = true
}

local soft_cons = {
	 = "g",  = "c"
}

local ea_cons = {
	 = true,  = true,  = true,  = true,  = true,  = true,  = true
}

local function is_letter(this)
	return this and match(this, "%w") and true or false
end

local export = {}

function export.tr(text, lang, sc)
	-- Only support modern Cyrillic (for now).
	if sc ~= "Cyrl" then
		return nil
	end
	
	local caps = {}
	text = gsub(text, "()(%u)", function(pos, this)
		caps = true
		return this:ulower()
	end)
	
	text = explode(text)
	
	local output, i, prev, this, nxt = {}, 0
	while i <= #text do
		prev, this, nxt = text, text, text
		if soft_cons then
			if ei_vowel_nxt then
				this = soft_cons
			elseif nxt == "а" then
				this = soft_cons .. "e"
			end
		elseif this == "ё" and i_vowel_prev then
			this = "o"
		elseif this == "г" and ei_vowel_nxt then
			this = "gh"
		elseif this == "и" and prev == "и" and not is_letter(nxt) then
			this = "ii"
		elseif this == "к" then
			if ei_vowel_nxt then
				this = "ch"
			elseif nxt == "з" or nxt == "с" then
				this = "x"
				i = i + 1
			end
		elseif this == "ю" and i_vowel_prev then
			this = "u"
		elseif this == "я" then
			if i_vowel_prev then
				this = "a"
			elseif ea_cons then
				this = "ea"
			end
		end
		this = letters or this
		insert(output, caps and gsub(this, "^.", uupper) or this)
		i = i + 1
	end
	
	return concat(output)
end

return export