Module:tet-sortkey

Hello, you have come here looking for the meaning of the word Module:tet-sortkey. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:tet-sortkey, but we will also tell you about its etymology, its characteristics and you will know how to say Module:tet-sortkey in singular and plural. Everything you need to know about the word Module:tet-sortkey you have here. The definition of the word Module:tet-sortkey will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:tet-sortkey, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will sort Tetum language text. 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:tet-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.

Alphabetic order: a b c d e f g h i j k l m n ñ ng o p r s t u v w x z.


local export = {}
local u = mw.ustring.char
local a, b = u(0xF000), u(0xF001)

local oneChar = {
		 = "a" .. a,  = "e" .. a,  = "i" .. a,  = "o" .. a,  = "u" .. a,  = "n" .. a
}

function export.makeSortKey(text, lang, sc)
	
	text = mw.ustring.gsub(text, "()(+)", "%2%1")
	
	for from, to in pairs(twoChars) do
		text = text:gsub(from, to)
	end
	
	return mw.ustring.upper(mw.ustring.gsub(mw.ustring.toNFC(text), ".", oneChar))
end

local tl = require("Module:languages").getByCode("tl")
local function tag(text)
	return require("Module:script utilities").tag_text(text, tl)
end

local showsubst = {
	 = "₂",
}

function export.showSortkey(frame)
	local output = {}
	
	for _, word in ipairs(frame.args) do
		local sc = tl:findBestScript(word):getCode()
		local sortkey = mw.ustring.gsub(export.makeSortKey(word, "tet", sc), ".", showsubst)
		sortkey = mw.ustring.gsub(sortkey, "()$", "%1¹")
		sortkey = mw.ustring.gsub(sortkey, "()(%s)", "%1¹%2")
		local example = "\n* <code>" .. sortkey .. "</code>\n: " .. tag(word)
		table.insert(output, example)
	end
	
	return table.concat(output)
end

function export.showSorting(frame)
	local terms = {}
	
	for _, term in ipairs(frame.args) do
		table.insert(terms, term)
	end
	
	local makeSortKey = require("Module:memoize")(export.makeSortKey)
	local function comp(term1, term2)
		return makeSortKey(term1) < makeSortKey(term2)
	end
	
	table.sort(terms, comp)
	
	for i, term in pairs(terms) do
		local sc = tl:findBestScript(term):getCode()
		local sortkey = mw.ustring.gsub(export.makeSortKey(term, "tet", sc), ".", showsubst)
		sortkey = mw.ustring.gsub(sortkey, "()$", "%1¹")
		sortkey = mw.ustring.gsub(sortkey, "()(%s)", "%1¹%2")
		terms = "\n* " .. tag(term) .. " (<code>" .. sortkey .. "</code>)"
	end
	
	return table.concat(terms)
end

return export