Module:mdf-translit

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

This module will transliterate Moksha language text per WT:MDF 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:mdf-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 gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local trim = mw.text.trim

-- apply gsub() repeatedly until no change
local function gsub_repeatedly(term, foo, bar)
	while true do
		local new_term = gsub(term, foo, bar)
		if new_term == term then
			return term
		end
		term = new_term
	end
end

local letters = {
	="A", ="B", ="V", ="G", ="D", ="E", ="O", ="Ž", ="Z", ="I", ="J",
	="K", ="L", ="M", ="N", ="O", ="P", ="R", ="S", ="T", ="U", ="F",
	="H", ="C", ="Č", ="Š", ="Šč", ="Ə", ="I", ="", ="E", ="U", ="A",
	="Ä", ="E", ="Ŋ", ="I", ="Kv",
	="a", ="b", ="v", ="g", ="d", ="e", ="o", ="ž", ="z", ="i", ="j",
	="k", ="l", ="m", ="n", ="o", ="p", ="r", ="s", ="t", ="u", ="f",
	="h", ="c", ="č", ="š", ="šč", ="ə", ="i", ="", ="e", ="u", ="a",
	="ä", ="e", ="ŋ", ="i", ="kv"
}

local palatals = {
	="Ď",  = "Ź",  = "Ľ",  = "Ń",  = "Ŕ",  = "Ś",  = "Ť",  = "Ć",
	="ď",  = "ź",  = "ľ",  = "ń",  = "ŕ",  = "ś",  = "ť",  = "ć",
}

local vowels = "АОУЫЭЯЁЮИЕЬаоуыэяёюиеь"
local front = "ЕЁИЮЯеёиюя"
local accents = "́̀"
local nondentals = "бвгжкпмшБВГЖКПМШ"

function export.tr(text, lang, sc)
	-- make all word borders have a space
	text = " " .. text .. " "

	-- front vowels after another vowel are written with initial j
	text = gsub_repeatedly(text, "(?)()", "%1j%2")
	text = gsub_repeatedly(text, "(?)()", "%1J%2")
	-- е, ё, ю, я at the beginning of a word are also written with initial j
	text = gsub(text, " ()", " j%1")
	text = gsub(text, " ()", " J%1")

	-- я after non-dental consonants becomes ä
	text = gsub(text, "()я", "%1ä")
	text = gsub(text, "()Я", "%1Ä")
	-- ё after non-dental consonants becomes œ
	text = gsub(text, "()ё", "%1ö")
	text = gsub(text, "()Ё", "%1Ö")

	-- make Е, Ё, Ю, Я lowercase if preceding a non-capital letter
	text = gsub(text, "()()", function(v, l)
		return lower(v) .. l
	end)

	-- palatalize any sequence of dental consonants before ь
	text = gsub(text, "(*л?)ь", function(cluster)
		return mw.ustring.gsub(cluster, ".", palatals)
	end)

	-- palatalize any sequence of dental consonants before front vowels
	text = gsub(text, "(*л?)()", function(cluster, frontVowel)
		return mw.ustring.gsub(cluster, ".", palatals) .. frontVowel
	end)

	-- ъ and ь are omitted before a front vowel
	text = gsub(text, "ъ()","j%1")
	text = gsub(text, "Ъ()","J%1")

	return trim(gsub(text, ".", letters))
end

return export