Module:Hebr-Arab-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Hebrew script. 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:Hebr-Arab-translit/testcases.

Functions

[edit]
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 gsub = mw.ustring.gsub
local match = mw.ustring.match

local letters = "קראטוןםפףךלחיעכגדשזסבהנמצתץ"
local dagesh = "ּ"
local diacritics = "ְֱֲֲֳִֵֶַָָֻּ"

local tt = {
	['ב']='ب',  ['ג']='ج',['דּ']='د',['ד']='ذ',['ה']='ه',['ו']='و',['ז']='ز',	['ח']='ح',['ט']='ط',['י']='ي',
	['כּ']='ك', -- intital form
	['כ']='ك', -- intial form 
	['ךּ']='ك', -- final form, with dagesh = strong k sound
	['ך']='ك', -- final form
	['ל']='ل',['מ']='م',['ם']='م',['נ']='ن',['ן']='ن',
	['ס']='س', -- no direct equivalent
	['ע']='ع',['פ']='ف',['ף']='ف',['צ']='ص',['ץ']='ص',['ק']='ق',['ר']='ر',['שׁ']='ش',['שׂ']='س',['ש']='ش',
	['ת']='ث',
	['א']='أ',
	
	['ַ']='َ',-- Patach/fatah
	['ִ']='ِ', -- Hiriq/Damma
	['ָ']='ٰ', -- Qamatz/Khanjariyah
	['ְ']='ْ',-- Shva/Sukun
	['ֹ']='و'-- Holam
}
function export.tr(text, lang, sc)

	-- fixes the double diacritic issues
	
    text = gsub(text, "פ" .. '([' .. diacritics .. '])' .. dagesh, "ف%1")
    
	text = mw.ustring.gsub(text, '([\214\176\214\177\214\178\214\179\214\180\214\181\214\182\214\183\214\184\214\187])([\214\185\214\188\215\129\215\130])', "%2%1")
	text = mw.ustring.gsub(text, '.[\214\185\214\188\215\129\215\130]', tt)
	--
	
	text = gsub(text, "תּ","ت")
	text = gsub(text, "וֹ","و")
	text = gsub(text, "וּ","ُو")
		
	text = mw.ustring.gsub(text, '.', tt)

	return text
end
return export