Module:hi-translit

Hello, you have come here looking for the meaning of the word Module:hi-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:hi-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:hi-translit in singular and plural. Everything you need to know about the word Module:hi-translit you have here. The definition of the word Module:hi-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:hi-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate Hindi language text per WT:HI TR. It is also used to transliterate Angika, Awadhi, Bagheli, Mahasu Pahari, Haryanvi, Bhadrawahi, Bundeli, Palya Bareli, Braj, Chambeali, Churahi, Dhundhari, Dogri, Gaddi, Garhwali, Chhattisgarhi, Hadothi, Jaunsari, Bilaspuri, Kullu Pahari, Kurukh, Mandeali, Mewari, Malvi, Marwari, Nimadi, Pangwali, Sadri, Saraiki, Mundari, Mewati, and Kangri. 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:hi-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

-- Transliteration for Hindi (possibly other languages using Devanagari script, except for Sanskrit)
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 plain_gsub = m_str_utils.plain_gsub
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',
	 = 'q',  = 'x',  = 'ġ',  = 'ḻ',
	 = 'z',  = 'ẓ',  = 'ź',  = 'ṛ',  = 'ṛh',
	 = 'f',  = 'ṉ',  = 'ṟ',  = 'ẏ',  = 'w',
	--  = 'jñ',

	-- 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_short = {
	 = 'ङ',  = 'ङ',  = 'ङ',  = 'ङ',  = 'ङ',
	 = 'ञ',  = 'ञ',  = 'ञ',  = 'ञ',  = 'ञ',  
	 = 'ण',  = 'ण',  = 'ण',  = 'ण',  = 'ण',
	 = 'न',  = 'न',  = 'न',  = 'न',  = 'न',
	 = 'म',  = 'म',  = 'म',  = 'म',  = 'म',
	 = 'ँ',  = 'न',  = 'न',   = 'म',
	 = 'ञ',  = 'ण',  = 'न',  = 'ँ',
	 = 'न',  = 'म',   = 'ङ',  = 'ङ',  = 'ङ',
	 = 'ँ',  = 'ँ'
}

local nasal_assim_long = {
	 = 'ँ',  = 'ँ',  = 'ङ',  = 'ङ',  = 'ँ',
	 = 'ँ',  = 'ँ',  = 'ञ',  = 'ञ',  = 'ँ',  
	 = 'ँ',  = 'ँ',  = 'ण',  = 'ण',  = 'ँ',
	 = 'ँ',  = 'ँ',  = 'न',  = 'न',  = 'ँ',
	 = 'ँ',  = 'ँ',  = 'म',  = 'म',  = 'ँ',
	 = 'ँ',
	 = 'न',  = 'म',   = 'ङ',  = 'ङ',  = 'ङ',
	 = 'ँ',  = 'ँ'
}

-- These clusters when occurring word-finally will not trigger a schwa added
-- after them even though the second consonant is in special_cons, which normally
-- causes the extra schwa to be added. NOTE: The clusters are reversed from their
-- ultimate effect, e.g. the first cluster is written 'ml' but actually applies
-- to words ending in 'lm'. The clusters below overall refer to the six clusters
-- describable by , i.e. rm, rn, rv, lm, ln, lv (plus rṇ).
-- Plus some word-final geminates.
local perm_cl = {
	 = true,  = true,  = true,
	 = true,  = true,  = true,  = true,
	 = true,  = true,  = true,  = true,  = true
}

local all_cons, special_cons = 'कखगघङचछजझञटठडढणतथदधनपफबभमयरलवषशसह', 'यरलवहनमञण'
local vowel, vowel_sign = '*aिुृेोाीूैौॉॅॆॊ\'', 'अइउएओआईऊऋऐऔऑऍ\''
local long_vowel, short_vowel = 'ाीूेैोौआईऊएऐओऔ', '*aिुृॆॊॅॉअइउऋऍऑऎऒ\''
local syncope_pattern = '()(़?)a(़?)(?)'

function export.tr(text, lang, sc)
	-- treat anusvara + nasal as geminate nasal after short vowels
	text = gsub(text, '()ं()', '%1%2्%2')
	-- word-final apostrophe (e.g. from bold formatting) does not delete schwa
	text = gsub(text, '(़?)(\'%A)', '%1a%2')
	text = gsub(text, '(़?)(\')$', '%1a%2')
	text = gsub(text, '(़?)(?)', function(c, d)
		return c .. (d == "" and 'a' or d) end)
	-- to detect words, include Unicode 0900-0963 and 0971-097F (plus 'a' and '*'),
	-- excluding e.g. danda and abbreviation dot ॰
	for word in gmatch(text, "+") do
		local orig_word = word
		word = reverse(word)
		word = gsub(word, '^a(़?)()(.)(.?)', function(opt, first, second, third)
			return (((match(first, '') and match(second, '्') and not perm_cl)
				or match(first .. second, 'य'))
				and 'a' or "") .. opt .. first .. second .. third end)
		while match(word, syncope_pattern) do
			word = gsub(word, syncope_pattern, '%1%2%3%4')
		end
		word = reverse(word)
		-- The special_vowel category consists of ī/e/o/ai/au, these vowels are often 
		-- written with anusvara for 'aesthetic' reasons as the vowel diacritic 
		-- gets in the way of the candrabindu. For ī/e/o/ai/au, anusvara will trigger 
		-- nasal_assim_long and candrabindu will force a nasal vowel. To force a nasal 
		-- consonant before voiceless stops (mostly in loanwords), respell with 
		-- homorganic nasal ङ/ञ/ण/न/म + virama ्
		-- Exception: vowel 'e' when written as standalone ए
        local special_vowel, normal_vowel = 'ीेैोौईऐओऔ', '*aिुाूृॆॅॊॉअइउआऊऋऎऍऒऑए\''
        word = gsub(word, '()ँ(.़?)', function(prev, succ)
			return prev .. "̃" .. succ
		end)
		--sometimes chandrabindu != anusvara
		word = gsub(word, '()ं(़?)', function(prev, succ)
			return prev .. (nasal_assim_short or "̃") .. succ
		end)
		word = gsub(word, '()ँ(़?)', function(prev, succ)
			return prev .. "̃" .. succ
		end)
		--force chandrabindu to behave as anusvara
		word = gsub(word, 'ँ', 'ं')
		word = gsub(word, '()ं(.़?)', function(prev, succ)
			return prev .. (nasal_assim_short or "̃") .. succ
		end)
		word = gsub(word, '()ं(.़?)', function(prev, succ)
			return prev .. (nasal_assim_long or "̃") .. succ
		end)
		text = plain_gsub(text, orig_word, word)
	end
	text = gsub(text, '.़?', conv)
	text = gsub(text, 'a()̃', 'a͠%1')
    text = gsub(text, 'ñz', 'nz')
    text = gsub(text, '%*', 'a')
	return toNFC(text)
end

return export