This module will transliterate ภาษาฮีบรู 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:he-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.

local export = {}
local u = mw.ustring.char
 
local tt = {
	['א'] = 'อ',
	['בּ'] = 'บ', ['ב'] = 'วฺ',
	['גּ'] = 'กฺ', ['ג'] = 'กฺ', ['גּ׳'] = 'จ', ['ג׳'] = 'จ',
	['דּ'] = 'ด', ['ד'] = 'ด', ['ד׳'] = 'ฑ',
	['ה'] = 'ฮ', ['הּ'] = 'ฮ',
	['ו'] = 'ว', ['וּ'] = 'ู', ['וֹ'] = '↶โ', ['ו׳'] = 'ว',
	['ז'] = 'ซฺ', ['ז׳'] = 'ฌฺ',
	['ח'] = 'ห',
	['ט'] = 'ต',
	['י'] = 'ย',
	['כּ'] = 'ก', ['כ'] = 'ฅ', ['ךּ'] = 'ก', ['ך'] = 'ฅ',
	['ל'] = 'ล',
	['מ'] = 'ม', ['ם'] = 'ม',
	['נ'] = 'น', ['ן'] = 'น',
	['ס'] = 'ซ',
	['ע'] = 'อฺ',
	['פּ'] = 'ป', ['פ'] = 'ฟ', ['ף'] = 'ฟ',
	['צ'] = 'ต͡ซ', ['ץ'] = 'ต͡ซ', ['צ׳'] = 'ช', ['ץ׳'] = 'ช',
	['ק'] = 'ก',
	['ר'] = 'ร',
	['ש'] = 'ซ', ['שׁ'] = 'ฌ', ['שׂ'] = 'ซ',
	['תּ'] = 'ต', ['ת'] = 'ต', ['ת׳'] = 'ธ',

	--
	[u(0x05B0)] = '', -- HEBREW POINT SHEVA
	[u(0x05B1)] = '↶เะ', -- HEBREW POINT HATAF SEGOL
	[u(0x05B2)] = 'ะ', -- HEBREW POINT HATAF PATAH
	[u(0x05B3)] = '↶โะ', -- HEBREW POINT HATAF QAMATS
	[u(0x05B4)] = 'ิ', -- HEBREW POINT HIRIQ
	[u(0x05B5)] = '↶เ', -- HEBREW POINT TSERE
	[u(0x05B6)] = '↶เ', -- HEBREW POINT SEGOL
	[u(0x05B7)] = 'า', -- HEBREW POINT PATAH
	[u(0x05B8)] = 'า', -- HEBREW POINT QAMATS
	[u(0x05C7)] = '↶โ', -- HEBREW POINT QAMATS QATAN
	[u(0x05B9)] = '↶โ', -- HEBREW POINT HOLAM

	[u(0x05BB)] = 'ุ', -- HEBREW POINT QUBUTS
	[u(0x05BC)] = '', -- HEBREW POINT DAGESH OR MAPIQ

	[u(0x05C1)] = '', -- HEBREW POINT SHIN DOT
	[u(0x05C2)] = '', -- HEBREW POINT SIN DOT

	--
	['־'] = '-', -- HEBREW PUNCTUATION MAQAF
	['׳'] = '′', -- HEBREW PUNCTUATION GERESH
	['״'] = '″', -- HEBREW PUNCTUATION GERSHAYIM
}

function export.tr(text, lang, sc)

	if type(text) == 'table' then -- called directly from a template
		text = text.args[1]
	end

	text = text:gsub('חַ$','ะห์'):gsub('חַ(%s)','ะห์%1')
	text = text:gsub('עַ$','ะอ์'):gsub('עַ(%s)','ะอ์%1')
	text = text:gsub('הַּ$','ะฮ์'):gsub('הַּ(%s)','ะฮ์%1')
	text = mw.ustring.gsub(text, '(['..u(0x05B0)..'-'..u(0x05B8)..u(0x05BB)..u(0x05C7)..'])(['..u(0x05B9)..u(0x05BC)..u(0x05C1)..u(0x05C2)..']+)', '%2%1')
	text = mw.ustring.gsub(text, '(['..u(0x05BC)..'])(['..u(0x05C1)..u(0x05C2)..'])', '%2%1')
	text = mw.ustring.gsub(text, '.['..u(0x05B9)..u(0x05BC)..u(0x05C1)..u(0x05C2)..'׳]', tt)
	text = mw.ustring.gsub(text, '.', tt)

	text = mw.ustring.gsub(text, '(.ฺ?)↶(.)', '%2%1')
	text = mw.ustring.gsub(text, 'ิย', 'ิย์')
	text = mw.ustring.gsub(text, 'ุว', 'ุว์')
	text = mw.ustring.gsub(text, 'าู', 'าว')

	return text

end

return export