Module:he-common: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
No edit summary
mNo edit summary
Line 8: Line 8:


function export.end_with_makaf(string)
function export.end_with_makaf(string)
if mw.ustring.char(-1) ~= "־" then
if mw.ustring.sub(string, -1) ~= "־" then
string = string .. "־"
string = string .. "־"
end
end

Revision as of 18:25, 3 November 2015

This module holds some common used functions for Hebrew, that are needed by other modules.


local export = {}
local lang = require("Module:languages").getByCode("he")

-- A nil-safe, Hebrew-specific diacritic remover.
function export.remove_nikud(formwv)
	return formwv and lang:makeEntryName(formwv)
end

function export.end_with_makaf(string)
	if mw.ustring.sub(string, -1) ~= "־" then
		string = string .. "־"
	end
	return string
end

-- This should only be used by modules that auto-generate words, otherwise use gen_link
function export.process_wv_triad(form, formwv, formdwv)
	if form then
		return form, formwv, formdwv
	elseif formwv then
		return export.remove_nikud(formwv), formwv, formdwv
	else
		return export.remove_nikud(formdwv), formdwv, nil
	end
end

function export.gen_link(form, formwv, formdwv)
	form, formwv, formdwv = export.process_wv_triad(form, formwv, formdwv)
	if not form then
		error("Can't make a link out of nothing.")
	end
	if formdwv then
		return "[[" .. form .. "|" .. (formwv or form) .. " \\ " .. formdwv .. "]]"
	else
		return "[[" .. form .. "|" .. (formwv or form) .. "]]"
	end
end

-- Like gen_link for construct forms appends a makaf if one doesn't already exist
function export.gen_link_ending_with_makaf(form, formwv, formdwv)
	form, formwv, formdwv = export.process_wv_triad(form, formwv, formdwv)
	if not form then
		error("Can't make a link out of nothing.")
	end
	if formdwv then
		return "[[" .. form .. "|" .. (export.end_with_makaf(formwv) or form) .. " \\ " .. export.end_with_makaf(formdwv) .. "]]"
	else
		return "[[" .. form .. "|" .. export.end_with_makaf(formwv or form) .. "]]"
	end
end

return export