Module:new-Newa-translit
Jump to navigation
Jump to search
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list โข links โข transclusions โข testcases โข sandbox
This module will transliterate Newar 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:new-Newa-translit/testcases.
Functions
[edit]tr(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
.
-- Transliteration for Newar in Newa script
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
['๐'] = 'k', ['๐'] = 'kh', ['๐'] = 'g', ['๐'] = 'gh', ['๐'] = 'แน
', ['๐'] = 'แน
h',
['๐'] = 'c', ['๐'] = 'ch', ['๐'] = 'j', ['๐'] = 'jh', ['๐'] = 'รฑ', ['๐'] = 'รฑh',
['๐'] = 'แนญ', ['๐'] = 'แนญh', ['๐'] = 'แธ', ['๐'] = 'แธh', ['๐'] = 'แน',
['๐'] = 't', ['๐ '] = 'th', ['๐ก'] = 'd', ['๐ข'] = 'dh', ['๐ฃ'] = 'n', ['๐ค'] ='nh',
['๐ฅ'] = 'p', ['๐ฆ'] = 'ph', ['๐ง'] = 'b', ['๐จ'] = 'bh', ['๐ฉ'] = 'm', ['๐ช'] ='mh',
['๐ซ'] = 'y', ['๐ฌ'] = 'r', ['๐ญ'] = 'rh', ['๐ฎ'] = 'l', ['๐ฏ'] = 'lh', ['๐ฐ'] = 'w', ['๐ฑ'] = 'ล', ['๐ฒ'] = 'แนฃ', ['๐ณ'] = 's', ['๐ด'] = 'h',
-- vowel diacritics
['๐ถ'] = 'i', ['๐ธ'] = 'u', ['๐พ'] = 'e', ['๐'] = 'o', ['๐ต'] = 'ฤ', ['๐ท'] = 'ฤซ', ['๐น'] = 'ลซ', ['๐บ'] = 'rฬฅ', ['๐ป'] = 'rฬฅฬ', ['๐ผ'] = 'lฬฅ', ['๐ฝ'] = 'lฬฅฬ', ['๐ฟ'] = 'ai', ['๐'] = 'au',
-- vowels
['๐'] = 'a', ['๐'] = 'i', ['๐'] = 'u', ['๐'] = 'e', ['๐'] = 'o', ['๐'] = 'ฤ', ['๐'] = 'ฤซ', ['๐
'] = 'ลซ', ['๐'] = 'rฬฅ', ['๐'] = 'rฬฅฬ', ['๐'] = 'lฬฅ', ['๐'] = 'lฬฅฬ', ['๐'] = 'ai', ['๐'] = 'au',
-- chandrabindu
['๐'] = 'ฬ',
-- anusvara
['๐'] = 'แน', ['๐'] = 'แน',
-- visarga
['๐
'] = 'แธฅ',
-- nuqta
['๐'] = '',
-- virama
['๐'] = '',
-- om
['๐'] = 'om',
-- avagraha
['๐']='โ',
-- numerals
['๐'] = '0', ['๐'] = '1', ['๐'] = '2', ['๐'] = '3', ['๐'] = '4', ['๐'] = '5', ['๐'] = '6', ['๐'] = '7', ['๐'] = '8', ['๐'] = '9',
-- punctuation
['๐'] = '.', -- danda
['๐'] = '.', -- double danda
['๐'] = '', -- comma
-- abbreviation sign
['๐'] = '.',
}
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, '([' .. all_cons .. ']๐?)([' .. vowel .. '๐]?)', function(c, d)
return c .. (d == "" and 'a' or d) end)
for word in mw.ustring.gmatch(text, "[๐-๐งa]+") do
local orig_word = word
word = rev_string(word)
word = gsub(word, '^a(๐?)([' .. all_cons .. '])(.)(.?)', function(opt, first, second, third)
return (((match(first, '[' .. special_cons .. ']') and match(second, '๐')
or match(first, '[' .. special_cons .. ']') and match(second, '๐') and not perm_cl[first..second..third])
or match(first .. second, '๐ซ[๐๐๐๐๐๐๐๐๐๐
๐๐๐๐a๐ผ๐ฝ๐พ๐ฟ๐๐๐ป๐บ๐น๐ธ๐ถ๐ต๐ท]') or match(first .. second, '๐ด[๐๐๐๐๐๐๐๐๐๐
๐๐๐๐a๐ผ๐ฝ๐พ๐ฟ๐๐๐ป๐บ๐น๐ธ๐ถ๐ต๐ท]'))
and 'a' or "") .. opt .. first .. second .. third end)
word = gsub(word, '(.?)๐(.)', function(succ, prev)
return succ .. (succ..prev == "" and "๐๐ฉ" or
(succ == "" and match(prev, '[' .. vowel .. ']') and "ฬ" or nasal_assim[succ] or "แน")) .. prev end)
local escaped_orig_word = gsub(orig_word, "%+", "") text = gsub(text, orig_word, rev_string(word))
text = gsub(text, '๐ซ๐', 'y') end
text = gsub(text, '.๐?', conv)
text = gsub(text, 'a([iu])ฬ', 'aอ %1')
text = gsub(text, "[<>]", "") return mw.ustring.toNFC(text)
end
return export