This module will transliterate Yamphu language text.
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:ybi-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 gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= 'k',
= 'kh',
= 'g',
= 'gh',
= 'ṅ',
= 'c',
= 'ch',
= 'j',
= 'jh',
= 'ñ',
= 'ṭ',
= 'ṭh',
= 'ḍ',
= 'ḍh',
= 'ṇ',
= 't',
= 'th',
= 'd',
= 'dh',
= 'n',
= 'p',
= 'ph',
= 'b',
= 'bh',
= 'm',
= 'y',
= 'r',
= 'l',
= 'w',
= 'ś',
= 'ṣ',
= 's',
= 'h',
= 'q',
= 'x',
= 'ġ',
= 'ḻ',
= 'ḷ',
= 'z',
= 'ž',
= 'ž',
= 'ṛ',
= 'ṛh',
= 'f',
= 'θ',
= 'ð',
= 'ṉ',
= 'ṟ',
= "'",
= 'V',
= 'ž',
-- vowel diacritics
= 'i',
= 'u',
= 'e',
= 'o',
= 'ā',
= 'ī',
= 'ū',
= 'r̥',
= 'r̥̄',
= 'l̥',
= 'l̥̄',
= 'ai',
= 'au',
= 'ŏ',
= 'ĕ',
-- vowel signs
= 'a',
= 'i',
= 'u',
= 'e',
= 'o',
= 'ā',
= 'ī',
= 'ū',
= 'r̥',
= 'r̥̄',
= 'l̥',
= 'l̥̄',
= 'ai',
= 'au',
= 'ŏ',
= 'ĕ',
= 'ĕ',
-- chandrabindu
= '̃',
-- anusvara
= 'ṃ',
-- visarga (length)
= ':',
-- virama
= '',
-- om
= 'om̐',
-- zero width joiner
= '',
-- zero width non joiner
= '',
-- numerals
= '0',
= '1',
= '2',
= '3',
= '4',
= '5',
= '6',
= '7',
= '8',
= '9',
-- punctuation
= '.', -- danda
= '.', -- double danda
= '', -- compound separator
-- abbreviation sign
= '.',
}
local nasal_assim = {
= 'ङ',
= 'ङ',
= 'ङ',
= 'ङ',
= 'ञ',
= 'ञ',
= 'ञ',
= 'ञ',
= 'ण',
= 'ण',
= 'ण',
= 'ण',
= 'म',
= 'म',
= 'म',
= 'म',
= 'म',
= 'न',
= 'न',
= 'न',
= 'न',
= 'न',
= 'न',
= 'ङ',
= 'न',
= 'म',
= 'म',
= 'ँ',
= 'म',
= 'ङ',
}
local perm_cl = {
= true, = true, = true, = true, = true, = true, = true
}
local all_cons, special_cons = 'कखगघङचछजझञटठडढणतथदधनपफबभमयरलवसशषह', 'कखगघचछजझटठडढणतथदधनपफबभमयरलवशषसह'
local vowel, vowel_sign = 'aिुृेोाीूैौॉॅॆॊॄॢॣ', 'अइउएओआईऊऋॠॡऌऐऔऑऍ'
local function rev_string(text)
local result, length = {}, mw.ustring.len(text)
for i = length, 1, -1 do
table.insert(result, mw.ustring.sub(text, i, i))
end
return table.concat(result)
end
function export.tr(text, lang, sc)
text = gsub(text, '(़?)(?)', function(c, d)
return c .. (d == "" and 'a' or d)
end)
for word in mw.ustring.gmatch(text, "+") do
local orig_word = word
word = rev_string(word)
word = gsub(word, '^a(़?)()(.)(.?)', function(opt, first, second, third)
return (((match(first, '') and match(second, 'ं')
or match(first, '') and match(second, '्') and not perm_cl)
or match(first .. second, 'य') or match(first .. second, 'ह'))
and 'a' or "") .. opt .. first .. second .. third
end)
word = gsub(word, '(.?)ं(.)', function(succ, prev)
return succ .. (succ .. prev == "a" and "्म" or
(succ == "" and match(prev, '') and "̃" or nasal_assim or "ṃ")) .. prev
end)
local escaped_orig_word = gsub(orig_word, "%+", "")
text = gsub(text, orig_word, rev_string(word))
text = gsub(text, 'ज्ञ', 'gy')
text = gsub(text, 'े़', 'ê')
text = gsub(text, 'ए़', 'ê')
end
text = gsub(text, '.़?', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, "", "")
text = gsub(text, "ॱ", "")
text = gsub(text, 'e़', 'ê')
text = gsub(text, 'rh̥', 'hr̥')
text = mw.ustring.toNFC(text)
return text
end
return export