Module:cau-cir-translit

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

This module will transliterate text in one of the Circassian languages. It is also used to transliterate Adyghe and Kabardian. 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:cau-cir-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 GRAVE, ACUTE, CIRC, MACRON, BREVE, CARON, DOTBELOW = u(0x300), u(0x301), u(0x302), u(0x304), u(0x306), u(0x30C), u(0x323)

local tt = {
	 = "a",  = "b",  = "v",  = "ɣ",  = "d",  = "e",  = "jo",  = "ž",  = "z",  = "i",  = "j",  = "k",  = "l",  = "m",  = "n",  = "o",  = "p",  = "r",  = "s",  = "t",  = "u",  = "f",  = "x",  = "c",  = "č",  = "š",  = "ś",  = "",  = "ə",  = "ʲ",  = "ɛ",  = "jəw",  = "ja",  = "ʼ",
	 = "A",  = "B",  = "V",  = "Ɣ",  = "D",  = "E",  = "Jo",  = "Ž",  = "Z",  = "I",  = "J",  = "K",  = "L",  = "M",  = "N",  = "O",  = "P",  = "R",  = "S",  = "T",  = "U",  = "F",  = "X",  = "C",  = "Č",  = "Š",  = "Ś",  = "",  = "Ə",  = "ʲ",  = "Ɛ",  = "Jəw",  = "Ja",  = "ʼ"
}

local digraphs = {
	 = "gʷo",  = "gʷu",  = "ğ",  = "gʲ",  = "ẑ",  = "ź",  = "kʷo",  = "kʷu",  = "q",  = "kʼ",  = "lˢ",  = "lᶻ",  = "lˢʼ",  = "pʼ",  = "sʼ",  = "tʼ",  = "fʼ",  = "xʷo",  = "xʷu",  = "χ",  = "ḥ",  = "cʷo",  = "cʷu",  = "cʼ",  = "ĉ",  = "ĉʼ",  = "ŝ",  = "šʼ",  = "śʼ",
	 = "Gʷo",  = "Gʷu",  = "Ğ",  = "Gʲ",  = "Ẑ",  = "Ź",  = "Kʷo",  = "Kʷu",  = "Q",  = "Kʼ",  = "Lˢ",  = "Lᶻ",  = "Lˢʼ",  = "Pʼ",  = "Sʼ",  = "Tʼ",  = "Fʼ",  = "Xʷo",  = "Xʷu",  = "Χ",  = "Ḥ",  = "Cʷo",  = "Cʷu",  = "Cʼ",  = "Ĉ",  = "Ĉʼ",  = "Ŝ",  = "Šʼ",  = "Śʼ"
}

-- Prevents overlapping substitutions (e.g. "лӏо"), and also ensures labialized consonants can be substituted before determining where "j" is placed in relation to "е" and "и".
local digraphs2 = {
	 = "je",  = "ji",  = "wo",  = "wu",  = "ʼwo",  = "ʼwu",
	 = "Je",  = "Ji",  = "Wo",  = "Wu",  = "ʼWo",  = "ʼWu"
}

local trigraphs = {
	 = "ğʷo",  = "ğʷu",  = "dzʷo",  = "dzʷu",  = "žʷo",  = "žʷu",  = "qχ",  = "qʷo",  = "qʷu",  = "qʼ",  = "kʷʼo",  = "kʷʼu",  = "pʷʼo",  = "pʷʼu",  = "tˡʼ",  = "tʷʼo",  = "tʷʼu",  = "χʷo",  = "χʷu",  = "ćʷo",  = "ćʷu",  = "šʷo",  = "šʷu",  = "šʷʼo",  = "šʷʼu",
	 = "Ğʷo",  = "Ğʷu",  = "Dzʷo",  = "Dzʷu",  = "Žʷo",  = "Žʷu",  = "Qχ",  = "Qʷo",  = "Qʷu",  = "Qʼ",  = "Kʷʼo",  = "Kʷʼu",  = "Pʷʼo",  = "Pʷʼu",  = "tˡʼ",  = "Tʷʼo",  = "Tʷʼu",  = "Χʷo",  = "Χʷu",  = "Ćʷo",  = "Ćʷu",  = "Šʷo",  = "Šʷu",  = "Šʷʼo",  = "Šʷʼu"
}

local tetragraphs = {
	 = "qχʷo",  = "qχʷu",
	 = "Qχʷo",  = "Qχʷu"
}

function export.tr(text, lang, sc)
	local UTF8_char = "*"
	
	-- Convert uppercase palochka to lowercase, along with any "false" palochkas (entered as Latin "I" or "l", Greek "Ι" or Cyrillic "І"). Lowercase palochka is found in tables above.
	text = mw.ustring.gsub(text, "", "ӏ")
	
	for tetragraph, replacement in pairs(tetragraphs) do
		text = text:gsub(tetragraph, replacement)
	end
	
	for trigraph, replacement in pairs(trigraphs) do
		text = text:gsub(trigraph, replacement)
	end
	
	for digraph, replacement in pairs(digraphs) do
		text = text:gsub(digraph, replacement)
	end
	
	-- Contextual addition of "j" before "е" and "и", and "w" before "о" and "у". NOTE: These break with string.gsub, so must use mw.ustring.gsub.
	text = mw.ustring.gsub(mw.ustring.toNFC(text), "^()", "j%1")
	text = mw.ustring.gsub(text, "^()", function(a) return "J" .. mw.ustring.lower(a) end)
	text = mw.ustring.gsub(text, "()()", "%1j%2")
	text = mw.ustring.gsub(text, "()()", function(a, b) return a .. "J" .. mw.ustring.lower(b) end)
	text = mw.ustring.gsub(text, "^()", "w%1")
	text = mw.ustring.gsub(text, "^()", function(a) return "W" .. mw.ustring.lower(a) end)
	text = mw.ustring.gsub(text, "()()", "%1w%2")
	text = mw.ustring.gsub(text, "()()", function(a, b) return a .. "W" .. mw.ustring.lower(b) end)
	
	for digraph, replacement in pairs(digraphs2) do
		text = text:gsub(digraph, replacement)
	end
	
	text = text:gsub(UTF8_char, tt)
	
	-- Remove epenthetic vowel for labialized consonants if before a non-iotated, non-labialized vowel.
	text = mw.ustring.gsub(text, "u()", "%1")
	
	-- Reposition apostrophes then decompose.
	text = mw.ustring.toNFD(mw.ustring.gsub(mw.ustring.gsub(text, "ʼʲ", "ʲʼ"), "ʼʷ", "ʷʼ"))
	
	-- When double letters both have a modifier letter and/or an apostrophe, only show on the second for readability purposes.
	for letter in ("abcdefghijklmnopqrstuvxzəɛɣχABCDEFGHIJKLMNOPQRSTUVXZƏƐƔΧ"):gmatch(UTF8_char) do
		text = mw.ustring.gsub(text, letter .. "(?)(?ʲ?ʼ?)" .. mw.ustring.lower(letter) .. "%1%2", letter .. "%1" .. mw.ustring.lower(letter) .. "%1%2")
	end
	
	-- Remove consecutive j/ʲ and w/ʷ then recompose.
	return mw.ustring.toNFC(mw.ustring.gsub(mw.ustring.gsub(text, "ʲ?()ʲ?", "%1"), "ʷ?()ʷ?", "%1"))
end

return export