Module:mn-translit

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

This module will transliterate Mongolian language text per WT:MN 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:mn-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 mn = require("Module:mn-common")
local gsub = mw.ustring.gsub
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local UTF8_char = "*"

local preConv = {
	 = "ө",  = "ө",  = "ү",
	 = "Ө",  = "Ө",  = "Ү"
}

local oneChar = {
	 = "a",  = "b",  = "v",  = "g",  = "d",  = "je",  = "jo",  = "ž",  = "z",  = "i",  = "j",  = "k",  = "l",  = "m",  = "n",  = "o",  = "ö",  = "p",  = "r",  = "s",  = "t",  = "u",  = "ü",  = "f",  = "x",  = "c",  = "č",  = "š",  = "šč",  = "ʺ",  = "y",  = "ʹ",  = "e",  = "ju",  = "ja",
	 = "A",  = "B",  = "V",  = "G",  = "D",  = "Je",  = "Jo",  = "Ž",  = "Z",  = "I",  = "J",  = "K",  = "L",  = "M",  = "N",  = "O",  = "Ö",  = "P",  = "R",  = "S",  = "T",  = "U",  = "Ü",  = "F",  = "X",  = "C",  = "Č",  = "Š",  = "Šč",  = "ʺ",  = "Y",  = "ʹ",  = "E",  = "Ju",  = "Ja"
}

local twoChars = {
	 = "ii",
	 = "Ii"
}

function export.tr(text, lang, sc)
	if sc ~= "Cyrl" then
		return nil
	end
	-- Pre-convert any substitute characters.
	text = text:gsub(UTF8_char, preConv)
	-- Decompose (except for "ё" and "й") so that accents can be consistently detected.
	text = toNFD(text)
	text = gsub(text, "̈", toNFC)
	text = gsub(text, "̆", toNFC)
	-- Hard sign does nothing if word-final (extremely rare, but attested in borrowings of affected Russian proper nouns like "Коммерсантъ").
	text = gsub(text, "()", "%1")
	text = gsub(text, "$", "")
	-- "Е" is not iotated after a consonant and "ю" is not iotated after "ж", "ш", "ч" or "щ", so they must be converted to their non-iotated romanizations in advance. However, a soft sign before "е" or "ю" (as a front vowel) creates a morphemic break, which means iotation does occur (i.e. it acts like a hard sign). These exceptions are converted into the iotated romanizations first; then, all instances of "е" and "ю" (which meet the prerequisites) are converted into non-iotated romanizations. This treats all instances of "ю" as front vowels, so deal with any back vowel instances of "ю" once iterating over the vowel harmonic segments later on, before doing the main substitutions.
	text = gsub(text, "()е", "%1je")
	text = gsub(text, "(ь)ю", "%1ju")
	text = gsub(text, "(?)е", "%1e")
	text = gsub(text, "(ь?)ю","%1u")
	-- Divide into segments by vowel harmony and iterate over them.
	text = mn.vowelharmony(text)
	text.translit = {}
	for i, v in ipairs(text) do
		-- "Ю" is "jü/ü" if front harmonic.
		if text.position == "front" then
			-- Latin "u" (from previous substitution).
			text.substring = gsub(text.substring, "u", "ü")
			-- Cyrillic "ю".
			text.substring = gsub(text.substring, "ю", "jü")
			text.substring = gsub(text.substring, "Ю", "Jü")
			-- "Е" is "jö/ö" if front round harmonic.
			if text.quality == "rounded" then
				-- Latin "e" (from previous substitution).
				text.substring = gsub(text.substring, "e", "ö")
				-- Cyrillic "е".
				text.substring = gsub(text.substring, "е", "jö")
				text.substring = gsub(text.substring, "Е", "Jö")
			end
		-- If back harmonic, any instances of "ю" that were treated as front vowels need to be treated as back vowels (i.e. the soft sign doesn't create a morphemic break, so iotation does not occur).
		else
			text.substring = gsub(text.substring, "()ju", "%1u")
		end
		-- Do primary substitutions. If still present, Cyrillic "е" becomes "je" and "ю" becomes "ju".
		for digraph, replacement in pairs(twoChars) do
			text.substring = text.substring:gsub(digraph, replacement)
		end
		text.substring = text.substring:gsub(UTF8_char, oneChar)
		table.insert(text.translit, text.substring)
	end
	
	return toNFC(table.concat(text.translit, ""))
end

return export