This module will transliterate Marathi language text per WT:MR TR. It is also used to transliterate Ahirani, Konkani, and 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-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 Marathi (in progress)
local export = {}
local m_str_utils = require("Module:string utilities")
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local match = m_str_utils.match
local reverse = m_str_utils.reverse
local toNFC = mw.ustring.toNFC
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',
-- = 'jñ',
-- not for page titles
= 'j̈', = 'j̈h', = 'ċ',
-- vowel diacritics
= 'i', = 'u', = 'e', = 'o',
= 'ā', = 'ī', = 'ū',
= 'ŕ',
= 'ai', = 'au',
= 'ŏ',
= 'ĕ',
-- vowel signs
= 'a', = 'i', = '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 = {
= 'ङ', = 'ङ', = 'ङ', = 'ङ',
= 'न', = 'न', = 'न',
= 'ञ', = 'ञ', = 'ञ', = 'ञ',
= 'ण', = 'ण', = 'ण', = 'ण',
= 'म', = 'म', = 'म', = 'म', = 'म',
= 'इ', = 'उ', = 'ल', = 'उ',
= 'उ', = 'उ', = 'उ', = 'उ',
}
local perm_cl = {
= true, = true, = true,
}
local all_cons, special_cons = 'कखगघङचछजझञटठडढतथदधपफबभशषसयरलवहणनमळ', 'दतयरलवहनम'
local vowel, vowel_sign = '%*aिुृेोाीूैौॉॅ', 'अइउएओआईऊऋऐऔऑऍ'
local syncope_pattern = '()(़?)a(़?)(?)'
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 gmatch(text, "+") do
local orig_word = word
word = reverse(word)
word = gsub(word, '^a(़?)', '%1')
while match(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 match(prev, '') and "̃" or nasal_assim or "n")) .. prev end)
text = gsub(text, orig_word, reverse(word))
end
text = gsub(text, '.़?', conv)
text = gsub(text, 'a()̃', 'a͠%1')
text = gsub(text, 'aa', 'a')
return toNFC(text)
end
return export