Module:he-translit

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
This module is still being disputed.
Do not use this module. This module was designed to follow WT:HE TR, which does not have consensus among the Hebrew editors; moreover, it does not follow WT:HE TR strictly.
This module will transliterate Hebrew language text per WT:HE TR.

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[edit]

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

local export = {}
local u = mw.ustring.char
 
local tt = {
	['א'] = '\'',
	['בּ'] = 'b', ['ב'] = 'v',
	['גּ'] = 'g', ['ג'] = 'g', ['גּ׳'] = 'j', ['ג׳'] = 'j',
	['דּ'] = 'd', ['ד'] = 'd', ['ד׳'] = 'dh',
	['ה'] = 'h', ['הּ'] = 'h',
	['ו'] = 'v', ['וּ'] = '(u/v)', ['וֹ'] = 'o', ['ו׳'] = 'w',
	['ז'] = 'z', ['ז׳'] = 'zh',
	['ח'] = 'kh',
	['ט'] = 't',
	['י'] = 'y',
	['כּ'] = 'k', ['כ'] = 'kh', ['ךּ'] = 'k', ['ך'] = 'kh',
	['ל'] = 'l',
	['מ'] = 'm', ['ם'] = 'm',
	['נ'] = 'n', ['ן'] = 'n',
	['ס'] = 's',
	['ע'] = '\'',
	['פּ'] = 'p', ['פ'] = 'f', ['ף'] = 'f',
	['צ'] = 'ts', ['ץ'] = 'ts', ['צ׳'] = 'ch', ['ץ׳'] = 'ch',
	['ק'] = 'k',
	['ר'] = 'r',
	['ש'] = '(s/sh)', ['שׁ'] = 'sh', ['שׂ'] = 's',
	['תּ'] = 't', ['ת'] = 't', ['ת׳'] = 'th',

	[u(0x05B0)] = '\'', -- HEBREW POINT SHEVA
	[u(0x05B1)] = 'e', -- HEBREW POINT HATAF SEGOL
	[u(0x05B2)] = 'a', -- HEBREW POINT HATAF PATAH
	[u(0x05B3)] = 'o', -- HEBREW POINT HATAF QAMATS
	[u(0x05B4)] = 'i', -- HEBREW POINT HIRIQ
	[u(0x05B5)] = 'ei', -- HEBREW POINT TSERE
	[u(0x05B6)] = 'e', -- HEBREW POINT SEGOL
	[u(0x05B7)] = 'a', -- HEBREW POINT PATAH
	[u(0x05B8)] = '(a/o)', -- HEBREW POINT QAMATS
	[u(0x05C7)] = 'o', -- HEBREW POINT QAMATS QATAN
	[u(0x05B9)] = 'o', -- HEBREW POINT HOLAM

	[u(0x05BB)] = 'u', -- 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)
	text = text:gsub('חַ$','akh'):gsub('חַ(%s)','akh%1')
	text = text:gsub('עַ$','a\''):gsub('עַ(%s)','a\'%1')
	text = text:gsub('הַּ$','ah'):gsub('הַּ(%s)','ah%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)

	return text
end

return export