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.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.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