Module:zlw-slv-entryname

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

This module will generate entry names for Slovincian 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:zlw-slv-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 u = require("Module:string/char")

local export = {}

-- U+02D8 COMBINING BREVE
-- U+0304 COMBINING MACRON

local pitch_accent = "[" .. u( 0x2D8, 0x304) .. "]"

function export.makeEntryName(text)
	-- Decompose to permit diacritics to be matched even in composed characters.
	text = mw.ustring.toNFD(text)
	
	text = mw.ustring.gsub(
		text,
		"[aioùu][" .. u(0x300) .. "-" .. u(0x36F) .. "]+",
		function(vowel)
			return mw.ustring.gsub(vowel, pitch_accent, "")
		end)
	
	-- Return back to native MediaWiki normalization.
	text = mw.ustring.toNFC(text)
	
	return text
end

return export