Modul:gu-translit
- Berikut merupakan pendokumenan yang dijana oleh Modul:pendokumenan/functions/translit. [sunting]
- Pautan berguna: senarai sublaman • pautan • transklusi • kes ujian • kotak pasir
Modul ini akan mentransliterasi Bahasa Gujarati teks. Ia juga digunakan untuk mentransliterasi Kachchi and Vaghri.
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:gu-translit/testcases.
Functions
suntingtr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - When the transliteration fails, returns
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', ['વ']='v', ['ળ']='ḷ',
['શ']='ś', ['ષ']='ṣ', ['સ']='s', ['હ']='h',
['ત઼']='t̰', ['જ઼']='z', ['ંઘ઼']='ng', ['ડ઼']='ṛ', ['ઢ઼']='ṛh', ['ન઼']='ṉ', ['ફ઼']='f',
--vowel diacritics
['ા']='ā', ['િ']='i', ['ી']='ī', ['ુ']='u', ['ૂ']='ū', ['ૃ']='ru', ['ૄ']='ṝ',
['ે']='e', ['ૈ']='ai', ['ો']='o', ['ૌ']='au', ['ૅ']='ɛ', ['ૉ']='ɔ',
-- vowel mātras
['અ']='a', ['આ']='ā', ['ઇ']='i', ['ઈ']='ī', ['ઉ']='u', ['ઊ']='ū', ['ઋ']='ru', ['ૠ']='ṝ',
['એ']='e', ['ઐ']='ai', ['ઓ']='o', ['ઔ']='au', ['ઍ']='ɛ', ['ઑ']='ɔ',
-- chandrabindu
['ઁ']='m̐', --until a better method is found
-- anusvara
['ં']='ṃ', --until a better method is found
-- visarga
['ઃ']='ḥ',
-- virama
['્']='',
-- avagraha
['ઽ']='’',
--numerals
['૦']='0', ['૧']='1', ['૨']='2', ['૩']='3', ['૪']='4', ['૫']='5', ['૬']='6', ['૭']='7', ['૮']='8', ['૯']='9',
--punctuation
['।']='.', --danda
['+'] = '', -- compound separator
}
local nasal_assim = {
['ક'] = 'ઙ', ['ખ'] = 'ઙ', ['ગ'] = 'ઙ', ['ઘ'] = 'ઙ',
['ચ'] = 'ઞ', ['છ'] = 'ઞ', ['જ'] = 'ઞ', ['ઝ'] = 'ઞ',
['ટ'] = 'ણ', ['ઠ'] = 'ણ', ['ડ'] = 'ણ', ['ઢ'] = 'ણ',
['પ'] = 'મ', ['ફ'] = 'મ', ['બ'] = 'મ', ['ભ'] = 'મ', ['મ'] = 'મ',
}
local all_cons, special_cons = 'કખગઘઙચછજઝઞટઠડઢતથદધપફબભશષસયરલવહણનમ', 'યરલવહનમ'
local vowel, vowel_sign = 'aાિીુૂેૈોૌૃૄૅૉ', 'અઆઇઈઉઊએઐઓઔઍઑઋૠ'
local syncope_pattern = '([' .. vowel .. vowel_sign .. '])([' .. all_cons .. '])a([' .. gsub(all_cons, "ય", "") .. '])(ं?[' .. vowel .. vowel_sign .. '])'
local function rev_string(text)
local result, length = '', mw.ustring.len(text)
for i = 1, length do
result = result .. mw.ustring.sub(text, length - i + 1, length - i + 1)
end
return result
end
function export.tr(text, lang, sc)
text = gsub(text, '([' .. all_cons .. ']઼?)([' .. vowel .. '્]?)', function(c, d)
return c .. (d == "" and 'a' or d) end)
local result = {}
for word in mw.text.gsplit(text, " ", true) do
word = rev_string(word)
word = gsub(word, '^a(઼?)([' .. all_cons .. '])(.)', function(opt, first, second)
return (((match(first, '[' .. special_cons .. ']') and match(second, '્')) or match(first .. second, 'ય[ીેૈ]'))
and 'a' or "") .. opt .. first .. second end)
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, '[' .. vowel .. ']') and "̃" or nasal_assim[succ] or "n")) .. prev end)
table.insert(result, rev_string(word))
end
text = table.concat(result, " ")
text = gsub(text, '.઼?', conv)
return mw.ustring.toNFC(text)
end
return export