Module:xal-translit

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

This module will transliterate Kalmyk language text per WT:XAL TR. It is also used to transliterate Sanskrit. 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:xal-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 u = require("Module:string/char")

local export = {}

local trtab = {
	 = "A" ,  = "a" , -- A
	 = "Ä" ,  = "ä" , -- SCHWA
	 = "B" ,  = "b" , -- BE
	 = "V" ,  = "v" , -- VE
	 = "G" ,  = "g" , -- GHE
	 = "Ğ" ,  = "ğ" , -- SHHA
	 = "D" ,  = "d" , -- DE
	                                  -- IE is handled specially
	 = "Yo",  = "yo", -- IO
	 = "Zh" ,  = "zh" , -- ZHE
	 = "J" ,  = "j" , -- ZHE WITH DESCENDER
	 = "Z" ,  = "z" , -- ZE
	 = "I" ,  = "i" , -- I
	 = "Y" ,  = "y" , -- SHORT I
	 = "K" ,  = "k" , -- KA
	 = "L" ,  = "l" , -- EL
	 = "M" ,  = "m" , -- EM
	 = "N" ,  = "n" , -- EN
	 = "Ñ" ,  = "ñ" , -- EN WITH DESCENDER
	 = "O" ,  = "o" , -- O
	 = "Ö" ,  = "ö" , -- BARRED O
	 = "P" ,  = "p" , -- PE
	 = "R" ,  = "r" , -- ER
	 = "S" ,  = "s" , -- ES
	 = "T" ,  = "t" , -- TE
	 = "U" ,  = "u" , -- U
	 = "Ü" ,  = "ü" , -- STRAIGHT U
	 = "F" ,  = "f" , -- EF
	 = "X" ,  = "x" , -- HA
	 = "Ts",  = "ts", -- TSE
	 = "Ç" ,  = "ç" , -- CHE
	 = "Ş" ,  = "ş" , -- SHA
	 = "Şç",  = "şç", -- SHCHA
	 = "ʺ" ,  = "ʺ" , -- HARD SIGN
	 = "Y" ,  = "y" , -- YERU
	 = "ʹ" ,  = "ʹ" , -- SOFT SIGN
	 = "E" ,  = "e" , -- E
	 = "Yu",  = "yu", -- YU
	 = "Ya",  = "ya"  -- YA
}

local gives_e = {
	 = true,  = true, -- SCHWA
	 = true,  = true, -- BE
	 = true,  = true, -- VE
	 = true,  = true, -- GHE
	 = true,  = true, -- SHHA
	 = true,  = true, -- DE
	 = true,  = true, -- ZHE
	 = true,  = true, -- ZHE WITH DESCENDER
	 = true,  = true, -- ZE
	 = true,  = true, -- SHORT I
	 = true,  = true, -- KA
	 = true,  = true, -- EL
	 = true,  = true, -- EM
	 = true,  = true, -- EN
	 = true,  = true, -- EN WITH DESCENDER
	 = true,  = true, -- PE
	 = true,  = true, -- ER
	 = true,  = true, -- ES
	 = true,  = true, -- TE
	 = true,  = true, -- EF
	 = true,  = true, -- HA
	 = true,  = true, -- TSE
	 = true,  = true, -- CHE
	 = true,  = true, -- SHA
	 = true,  = true,  -- SHCHA
	 = true,  = true  -- YE
}

local tt_Mong = {
	 = "ː",		 = "a",	 = "e",	 = "i",	 = "o",
	 = "ö",	 = "u",	 = "ü",	 = "n",	 = "ng",
	 = "b",	 = "p",	 = "x",	 = "g",	 = "m",	 = "l",	 = "s",	 = "š",
	 = "t",	 = "d",	 = "ċ",	 = "j",	 = "ć",
	 = "y",	 = "r",	 = "w",	 = "k",	 = "ģ",	 = "h",
	 = "ĵ",	 = "ń",	 = "ź",	 = "t",	 = "ž",
	 = "-",	 = "?",	 = "!",	 = ",",	 = "."
}

function export.tr(text, lang, sc)
	local result = {}
	local last = false
	
	for num in mw.ustring.gcodepoint(text) do
		if (num == 0x0415) or (num == 0x0435) then -- CYRILLIC CAPITAL/SMALL LETTER IE
			if gives_e then
				table.insert(result, num == 0x0415 and "E" or "e")
			else
				table.insert(result, num == 0x0415 and "Ye" or "ye")
			end
		else
			table.insert(result, trtab or u(num))
		end
		if (num ~= 0x0300) and (num ~= 0x0301) then -- COMBINING GRAVE/ACUTE ACCENT
			last = num
		end
	end

	return table.concat(result)
end

return export