Module:fr-sortkey

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will sort French language text. It is also used to sort Karipúna Creole French, Louisiana Creole French, Mauritian Creole, Norman, Picard, Réunion Creole French, Angevin, Bourbonnais-Berrichon, Bourguignon, Champenois, Franc-Comtois, Gallo, Lorrain, Orléanais, Poitevin-Saintongeais, Tourangeau, San Miguel Creole French, and Tay Boi. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{sortkey}}. Within a module, use Module:languages#Language:makeSortKey.

For testcases, see Module:fr-sortkey/testcases.

Functions

makeSortKey(text, lang, sc)
Generates a sortkey for a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the sort fails, returns nil.

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

local remove_diacritics = u(0x0300) .. "-" .. u(0x0302) .. u(0x0308) .. u(0x030A) .. u(0x0327) .. "'" -- grave, acute, circumflex, diaeresis, ring above, cedilla, apostrophe

local oneChar = {
	["æ"] = "ae", ["œ"] = "oe"
}

function export.makeSortKey(text, lang, sc)
	return mw.ustring.upper(mw.ustring.toNFC(mw.ustring.gsub(mw.ustring.toNFD(mw.ustring.gsub(mw.ustring.lower(text), ".", oneChar)), "[" .. remove_diacritics .. "]", ""))) -- decompose, remove appropriate diacritics, then recompose again
end

return export