This module will transliterate Bhojpuri language text. It is also used to transliterate Magahi.
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:bho-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.-- Transliteration for Bhojpuri
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', = 'v', = 'ḷ',
= 'ś', = 'ṣ', = 's', = 'h',
= 'ṛ', = 'ṛh',
-- = 'gy',
-- vowel diacritics
= 'i', = 'u', = 'ē', = 'e', = 'ō', = 'o',
= 'ā', = 'ī', = 'ū',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ',
= 'ː',
= 'aː',
-- vowel signs
= 'a', = 'i', = 'u', = 'ē', = 'e', = 'ō', = 'o',
= 'ā', = 'ī', = 'ū',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ',
= 'ü',
= 'ï',
= 'ōm',
-- chandrabindu
= '̃',
-- anusvara
= 'ṁ',
-- visarga
= 'ḥ',
-- virama
= '',
-- numerals
= '0', = '1', = '2', = '3', = '4',
= '5', = '6', = '7', = '8', = '9',
-- punctuation
= '.', -- danda
= '', -- compound separator
-- abbreviation sign
= '.',
}
local nasal_assim = {
= 'न',
= 'ङ', = 'ङ', = 'ङ', = 'ङ',
= 'ञ', = 'ञ', = 'ञ', = 'ञ',
= 'ण', = 'ण', = 'ण', = 'ण',
= 'म', = 'म', = 'म', = 'म', = 'म',
}
local perm_cl = {
= true, = true, = true,
}
local all_cons, special_cons = 'कखगघङचछजझञटठडढतथदधपफबभशषसयरलवहणनम', 'यरलवहनम'
local vowel, vowel_sign = 'aिुृेोाीूैौॉॅ꣱', 'अइउएओआईऊऋऐऔऑऍऽ꣱'
local syncope_pattern = '()(़?)a(़?)(?)'
local function rev_string(text)
local result, length = {}, mw.ustring.len(text)
for i = 1, length do
table.insert(result, mw.ustring.sub(text, length - i + 1, length - i + 1))
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)
local a = ""
if match(first, '')
and match(second, '्')
and not perm_cl
or match(first .. second, 'य') then
a = "a"
end
return a .. opt .. first .. second .. third
end
)
while match(word, syncope_pattern) do
word = gsub(word, syncope_pattern, '%1%2ᵊ%3%4')
end
word = gsub(
word,
'(.?)ं(.)',
function(succ, prev)
local mid = nasal_assim or "n"
if succ..prev == "a" then
mid = "्म"
elseif succ == "" and match(prev, '') then
mid = "̃"
end
return succ .. mid .. prev
end
)
text = gsub(text, orig_word, rev_string(word))
end
text = gsub(text, '.़?', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, 'ज्ञ', conv)
return mw.ustring.toNFC(text)
end
return export