This module will transliterate Marathi language text per WT:MR TR. It is also used to transliterate Varhadi.
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:mr-Modi-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 u = require("Module:string/char")
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local ZWJ = u(0x200D)
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',
= 'r',
-- = 'dny',
-- vowel diacritics
---- only in script charts: = 'i', ='ū',
= 'u', = 'e', = 'o',
= 'ā', = 'ī',
= 'ru',
= 'ai', = 'au',
-- = 'ŏ',
= 'ĕ',
-- vowel signs
---- only in script charts: = 'i', ='ū',
= 'a', = 'u', = 'e', = 'o',
= 'ā', = 'ī',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ', = 'ĕ',
= 'om',
-- chandrabindu
--- = '̃',
-- anusvara
= 'ṁ',
-- visarga
= 'ḥ',
-- virama
= '',
-- numerals
= '0', = '1', = '2', = '3', = '4',
= '5', = '6', = '7', = '8', = '9',
-- punctuation
= '.', -- danda
= '.', -- double danda
= '', -- compound separator
-- abbreviation sign
= '.',
}
local nasal_assim = {
= '𑘒', = '𑘒', = '𑘒', = '𑘒',
= '𑘗', = '𑘗', = '𑘗', = '𑘗',
= '𑘜', = '𑘜', = '𑘜', = '𑘜',
= '𑘦', = '𑘦', = '𑘦', = '𑘦', = '𑘦',
= 'i', = '𑘄', = '𑘩', = '𑘄',
= '𑘄', = '𑘄', = '𑘄', = '𑘄',
}
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 char_array, i = {}, 1
for char in string.gmatch(text, "*") do -- UTF-8 character pattern
char_array = char
i = i + 1
end
return table.concat(require("Module:table").reverse(char_array))
end
function export.tr(text, lang, sc)
-- text = gsub(text, 'ाँ', 'ॉ' .. 'ं')
-- text = gsub(text, 'ँ', 'ॅ' .. 'ं')
text = gsub(text, '()𑘽 ', '%1𑘀 ')
text = gsub(text, '()𑘽$', '%1𑘀')
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()', '%1')
while find(word, syncope_pattern) do
word = gsub(word, syncope_pattern, '%1%2%3%4')
end
word = gsub(word, '(.?)𑘽(.)', function(succ, prev)
return succ .. (succ..prev == "a" and "𑘿𑘦" or
(succ == "" and find(prev, '') and "̃" or nasal_assim or "n")) .. prev end)
text = gsub(text, orig_word, rev_string(word))
end
text = gsub(text, '.', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, 'aa', 'a')
text = gsub(text, 'ñjñ', 'ndny')
text = gsub(text, 'jñ', 'dny')
return mw.ustring.toNFC(text)
end
return export