Module:grk-mar-entryname

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

This module will generate entry names for Mariupol Greek language text. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{entryname}}. Within a module, use Module:languages#Language:makeEntryName.

For testcases, see Module:grk-mar-entryname/testcases.

Functions

makeEntryName(text, lang, sc)
Generates an entry name for a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When entry name generation fails, returns nil.

local export = {}
local u = mw.ustring.char

local remove_diacritics = u(0x030C) .. u(0x0324) .. u(0x032E) -- caron, diaeresis below, breve below

function export.makeEntryName(text, lang, sc)
	text = mw.ustring.toNFD(text) -- decompose
	if sc == "Cyrl" then -- if script is Cyrillic, remove acute accents
		text = mw.ustring.gsub(text, "[" .. u(0x0301) .. "]", "")
	end
	
	return mw.ustring.toNFC(mw.ustring.gsub(text, "[" .. remove_diacritics .. "]", "")) -- remove appropriate diacritics, then recompose again
end

return export