Module:tg-translit

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

This module will transliterate Tajik language text per WT:TG TR. It is also used to transliterate Wakhi and Yagnobi. 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:tg-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_string_utils = require("Module:string utilities")
local gsub = m_string_utils.gsub
local U = m_string_utils.char

local tt = {
	 = "t",  = "T",
	 = "r",  = "R",
	 = "f",  = "F",
	 = "yu",  = "Yu",
	 = "š",  = "Š",
	 = "h",  = "H",
	 = "ʾ",  = "ʾ",
	 = "n",  = "N",
	 = "p",  = "P",
	 = "y",  = "Y",
	 = "l",  = "L",
	 = "z",  = "Z",
	 = "e",  = "E",
	 = "g",  = "G",
	 = "b",  = "B",
	 = "u",  = "U",
	 = "s",  = "S",
	 = "x",  = "X",
	 = "č",  = "Č",
	 = "ya",  = "Ya",
	 = "m",  = "M",
	 = "o",  = "O",
	 = "i",  = "I", -- has dash word finally
	 = "yo",  = "Yo",
	 = "ž",  = "Ž",
	 = "k",  = "K",
	 = "d",  = "D",
	 = "v",  = "V",
	 = "a",  = "A",
	 = "j",  = "J",
	 = "ü",  = "Ü",
	 = "e",  = "E",
	 = "i",  = "I",
	 = "q",  = "Q",
	 = "ġ",  = "Ġ",
	-- dated, removed in the 1998 reform
	 = "Ts",  = "ts", -- replaced with "тс", sometimes "с"
	 = "Šč",  = "šč", -- replaced with "шч"
	 = "Y",  = "y", -- replaced with "и"
	 = "",  = "" -- removed entirely
};

-- No longer used in Tajik, only supported "just in case"
local RUS_accent = U(0x301)
local RUonly = "ЦцЩщЫыЬь" .. RUS_accent
-- Letters
local all_letters = "аАбБвАгГғҒдДеЕёЁжЖзЗиИйЙкКқҚлЛмИнНоОпПрРсСтТуУӯӮфФхХҳҲчЧҷҶшШъЪэЭюЮяЯ" .. RUonly
local a_letter = ""

function export.tr(text, lang, sc)
	if not sc then
		sc = require("Module:languages").getByCode(lang):findBestScript(text):getCode()
	end

	if sc ~= "Cyrl" then
		text = nil
	else
		text = gsub(text, "\\", "\\")
		text = gsub(text, "#", "\1")
		text = gsub(text, "^", "#")
		text = gsub(text, "$", "#")
		text = gsub(text, "(\n)", "#%1#")
		text = gsub(text, "(+)", "#%1#")
		text = gsub(text, "(И)" .. "(#)", "Ì%2" )
		text = gsub(text, "(и)" .. "(#)", "ì%2" )
		text = gsub(text, "(#)" .. "(" .. a_letter .. "?" .. ")" .. "ì" .. "(#)", "%1%2и%3" )
		text = gsub(text, "(#)" .. "(" .. a_letter .. "?" .. ")" .. "Ì" .. "(#)", "%1%2И%3" )
		text = gsub(text,
							   "(?)()",
							   function(a, e)
			local iotated = {
				 = 'йе',  = 'ЙЕ',
				 = 'йи',  = 'ЙИ', 
				 = '-йи',  = '-ЙИ', 
				 = 'йӣ',  = 'ЙӢ'				
			}
			return a .. iotated
							   end)
		text = text
			:gsub("#Е", 'Ye')
			:gsub("#е", 'ye')
		text = gsub(text, "ì", "-и" )
		text = gsub(text, "Ì", "-И" )
		text = gsub(text, "#", "")
		text = gsub(text, "\1", "#")
		text = gsub(text, '.', tt)
	end

	return text
end

return export