Module:ab-translit

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

This module will transliterate Abkhaz language text per WT:AB 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:ab-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 gmatch = require("Module:string utilities").gmatch
local gsub = require("Module:string utilities").gsub
local lower = require("Module:string utilities").lower
local u = require("Module:string/char")

local GRAVE, ACUTE, CIRC, BREVE, CARON, DOTBELOW = u(0x300), u(0x301), u(0x302), u(0x306), u(0x30C), u(0x323)

local tt = {
	 = "a",  = "b",  = "v",  = "g",  = "ğ",  = "ğ",  = "d",  = "e",  = "jo",  = "ẑ",  = "z",  = "ź",  = "dz",  = "i",  = "j",  = "kʼ",  = "k",  = "qʼ",  = "l",  = "m",  = "n",  = "o",  = "pʼ",  = "p",  = "p",  = "r",  = "s",  = "ś",  = "tʼ",  = "t",  = "u",  = "f",  = "x",  = "ḥ",  = "c",  = "cʼ",  = "č",  = "čʼ",  = "ĉ",  = "ĉʼ",  = "ŝ",  = "ə",  = "jʷ",  = "dẑ",  = "ʲ",  = "ʷ",  = "e",  = "ju",  = "ja",
	 = "A",  = "B",  = "V",  = "G",  = "Ğ",  = "Ğ",  = "D",  = "E",  = "Jo",  = "Ẑ",  = "Z",  = "Ź",  = "Dz",  = "I",  = "J",  = "Kʼ",  = "K",  = "Qʼ",  = "L",  = "M",  = "N",  = "O",  = "Pʼ",  = "P",  = "P",  = "R",  = "S",  = "Ś",  = "Tʼ",  = "T",  = "U",  = "F",  = "X",  = "Ḥ",  = "C",  = "Cʼ",  = "Č",  = "Čʼ",  = "Ĉ",  = "Ĉʼ",  = "Ŝ",  = "Ə",  = "Jʷ",  = "Dẑ",  = "ʲ",  = "ʷ",  = "E",  = "Ju",  = "Ja"
}

local digraphs = {
	 = "ž",  = "dź",  = "dź",  = "fʼ",  = "x̣",  = "ć",  = "ć",  = "ćʼ",  = "ćʼ",  = "š",  = "dž",
	 = "Ž",  = "Dź",  = "Dź",  = "Fʼ",  = "X̣",  = "Ć",  = "Ć",  = "Ćʼ",  = "Ćʼ",  = "Š",  = "Dž"
}

function export.tr(text, lang, sc)
	-- Contextual substitution of "w" for "у", "j" for "и" and "j" before "е".
	text = gsub(text, "у()", "w%1")
	text = gsub(text, "У()", "W%1")
	text = gsub(text, "()у", "%1w")
	text = gsub(text, "и()", "j%1")
	text = gsub(text, "И()", "J%1")
	text = gsub(text, "()и", "%1j")
	text = gsub(text, "()е", "%1jе")
	
	for digraph, replacement in pairs(digraphs) do
		text = gsub(text, digraph, replacement)
	end
	
	text = gsub(text, ".", tt)
	
	-- Reposition apostrophes then decompose.
	text = mw.ustring.toNFD(gsub(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 gmatch("abcdefghijklmnopqrstuvxzəABCDEFGHIJKLMNOPQRSTUVXZƏ", ".") do
		text = gsub(text, letter .. "(?)(??ʼ?)" .. lower(letter) .. "%1%2", letter .. "%1" .. lower(letter) .. "%1%2")
	end
	
	-- Remove consecutive j/ʲ and w/ʷ.
	text = gsub(text, "ʲ?ʲ?", function(m1) return gsub(m1, "ʲ", "") end)
	text = gsub(text, "ʷ?()ʷ?", "%1")
	
	return text
end

return export