This module will transliterate Abaza language text per WT:ABQ 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:abq-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 m_str_utils = require("Module:string utilities")
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local lower = m_str_utils.lower
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = m_str_utils.char
local GRAVE, ACUTE, CIRC, CARON, DOTBELOW = u(0x300), u(0x301), u(0x302), u(0x30C), u(0x323)
local export = {}
local tt = {
= "a", = "b", = "v", = "g", = "d", = "e", = "jo", = "ž", = "z", = "i", = "j", = "k", = "l", = "m", = "n", = "o", = "p", = "r", = "s", = "t", = "u", = "f", = "x", = "c", = "ć", = "š", = "ś", = "ʔ", = "ə", = "ʲ", = "e", = "ju", = "ja",
= "A", = "B", = "V", = "G", = "D", = "E", = "Jo", = "Ž", = "Z", = "I", = "J", = "K", = "L", = "M", = "N", = "O", = "P", = "R", = "S", = "T", = "U", = "F", = "X", = "C", = "Ć", = "Š", = "Ś", = "Ɂ", = "Ə", = "ʲ", = "E", = "Ju", = "Ja"
}
local digraphs = {
= "ɣ", = "ʻ", = "ź", = "qʼ", = "kʼ", = "pʼ", = "tˡ", = "tʼ", = "fʼ", = "q", = "ḥ", = "cʼ", = "ćʼ", = "čʼ",
= "Ɣ", = "ʻ", = "Ź", = "Qʼ", = "Kʼ", = "Pʼ", = "Tˡ", = "Tʼ", = "Fʼ", = "Q", = "Ḥ", = "Cʼ", = "Ćʼ", = "Čʼ"
}
-- Prevents overlapping substitutions.
local digraphs2 = {
= "lᶻ", = "lˢʼ",
= "Lᶻ", = "Lˢʼ"
}
function export.tr(text, lang, sc)
-- 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 = gsub(text, "", "ӏ")
-- Contextual substitution of "j" before "е", "w" for "у" and ʷ for "в".
text = gsub(text, "^е", "jе")
text = gsub(text, "^Е", "Jе")
text = gsub(text, "()е", "%1jе")
text = gsub(text, "()Е", "%1Jе")
text = gsub(text, "у()", "w%1")
text = gsub(text, "У()", "W%1")
text = gsub(text, "()у", "%1w")
text = gsub(text, "()в", "%1ʷ")
for digraph, replacement in pairs(digraphs) do
text = gsub(text, digraph, replacement)
end
for digraph, replacement in pairs(digraphs2) do
text = gsub(text, digraph, replacement)
end
text = gsub(text, ".", tt)
-- Reposition apostrophes then decompose.
text = 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/ʷ then recompose.
return toNFC(gsub(gsub(text, "ʲ?()ʲ?", "%1"), "ʷ?()ʷ?", "%1"))
end
return export