Documentation for this module may be created at မော်ဂျူး:la-correlatives/doc

local export = {}

local function make_edit_link(title)
	local URL = tostring(mw.uri.fullUrl(title, "action=edit"))
	return '<span class="plainlinks">[' .. URL .. ' edit]</span>'
end

-- Here, anything in template parameter notation, {{{thingy}}}, will be linked
-- with no transliteration, like {{l|la|thingy|tr=-}}.
local template =
[=[
<div class="NavFrame">
<div class="NavHead" align="left">[[Appendix:Latin correlatives|Latin correlatives]] <sup>(]=] .. make_edit_link("Module:la-correlatives") .. [=[)</sup></div>
<div class="NavContent" align="center">
{| class="wikitable"
! type !! interrogative !! indefinite !! (medial)<br/>demonstrative !! proximal<br/>demonstrative !! distal<br/>demonstrative !! relative !! indefinite<br/>relative !! identity !! other
|-
! basic
| {{{quis}}}, {{{quī}}} || {{{quis}}}, {{{quī}}}, {{{quīdam}}}, {{{aliquis}}}, {{{aliquī}}}, {{{quisque}}}, {{{quisquam}}}, {{{aliquisquam}}}, {{{quispiam}}}, {{{ūllus}}} || {{{is}}}, {{{iste}}}, {{{istic}}} || {{{hic}}} || {{{ille}}}, {{{illic}}} || {{{quī}}} || {{{quisquis}}}, {{{quīcumque}}} || {{{ipse}}}, {{{īdem}}}|| {{{alter}}}, {{{alius}}}
|-
! dual
| {{{uter}}} || {{{alteruter}}}, {{{uterque}}} || || || || {{{uter}}} || {{{utercumque}}} || ||
|-
! number
| {{{quot}}} || {{{aliquot}}} || {{{tot}}} || || || {{{quot}}} || {{{quotquot}}}, {{{quotcumque}}} || {{{totidem}}} ||
|-
! order
| {{{quotus}}} || || {{{totus}}} || || || {{{quotus}}} || {{{quotuscumque}}} ||  ||
|-
! quantity
| {{{quam}}} || {{{aliquam}}} || {{{tam}}} || || || {{{quam}}} || †{{{quamquam}}} || †{{{tamen}}}, †{{{tandem}}} ||
|-
! size
| {{{quantus}}} || {{{aliquantus}}} || {{{tantus}}} || || || {{{quantus}}} || {{{quantuscumque}}} || {{{tantusdem}}} ||
|-
! quality
| {{{quālis}}} || {{{aliquālis}}}  || {{{tālis}}} || || || {{{quālis}}} || {{{quālis}}}, {{{quāliscumque}}} ||  ||
|-
! manner
| {{{ut}}}, {{{quī}}}, {{{quō}}} {{{modō}}}, {{{quōmodo}}}, {{{quemadmodum}}} || {{{utique}}}, {{{quī}}}, {{{quōdam}}} {{{modō}}}, {{{aliquō}}} {{{modō}}} || {{{ita}}}, {{{sic}}}, {{{eō}}}/{{{istō}}} {{{modō}}} || {{{hōc}}} {{{modō}}} || {{{illō}}} {{{modō}}} || {{{ut}}}, {{{quī}}}, {{{quō}}} {{{modō}}}, {{{quōmodo}}}, {{{quemadmodum}}} || {{{utut}}}, {{{utcumque}}}, {{{quōmodocumque}}} || {{{item}}}, {{{itidem}}} || {{{aliter}}}, {{{aliōquī}}}, {{{alterō}}}/{{{aliō}}} {{{modō}}}
|-
! method,<br>path,<br>place
| {{{quā}}} || {{{aliquā}}}, {{{quāque}}} || {{{eā}}}, {{{istāc}}} || {{{hāc}}} || {{{illāc}}} || {{{quā}}} || {{{quāquā}}}, {{{quācumque}}} || {{{eādem}}} || {{{aliā}}}
|-
! place
| {{{ubi}}} || {{{alicubi}}}, {{{ubique}}}, {{{usquam}}}, {{{uspiam}}} || {{{ibi}}}, {{{istic}}} || {{{hīc}}} || {{{illīc}}} || {{{ubi}}} || {{{ubiubi}}}, {{{ubicumque}}} || {{{ibidem}}} || {{{alibī}}}, {{{aliās}}}
|-
! source
| {{{unde}}} || {{{alicunde}}}, {{{undeunde}}} || {{{inde}}}, {{{istinc}}} || {{{hinc}}} || {{{illinc}}} || {{{unde}}} || {{{undecumque}}} || {{{indidem}}} || {{{aliunde}}}
|-
! destination
| {{{quō}}}, {{{quōrsum}}} || {{{aliquō}}}, {{{quōquam}}}, {{{quōpiam}}}, °{{{aliquōvorsum}}} || {{{eō}}}, {{{istūc}}}, °{{{istōrsum}}} || {{{hūc}}}, °{{{hōrsum}}} || {{{illūc}}}, °{{{illōrsum}}} || {{{quō}}} || {{{quōquō}}}, {{{quōcumque}}} || {{{eōdem}}} || {{{aliō}}}, {{{aliorsum}}} 
|-
! time
| {{{quandō}}} || {{{quondam}}}, {{{aliquandō}}}, {{{quandōque}}}, {{{umquam}}} || {{{tum}}}, {{{tunc}}} || {{{num}}}, {{{nunc}}} || {{{ōlim}}} || {{{cum}}}, {{{quandō}}} || {{{cumque}}}, {{{quandōcumque}}}, {{{quandōque}}} || {{{simul}}} || {{{aliās}}}
|-
! exact time
| {{{quota}}} {{{hōra}}} || || {{{ea}}}/{{{ista}}} {{{hōra}}} || {{{hac}}} {{{hōra}}} || {{{illa}}} {{{hōra}}} || {{{quota}}} {{{hōra}}} || {{{quotacumque}}} {{{hōra}}} || {{{eadem}}} {{{hōra}}} || {{{altera}}}/{{{alia}}} {{{hōra}}}
|-
! repetition
| {{{quotiēns}}} || {{{aliquotiēns}}} || {{{totiēns}}} || || || {{{quotiēns}}} || {{{quotiēnscumque}}} || ||
|-
! multiplication
| {{{quotuplex}}} || || {{{totuplex}}} || || || {{{quotuplex}}} || || ||
|-
| colspan="10" | † Turned conjunction with original meaning somewhat dissimulated<br/>° Rare
|}</div></div>]=]

function export.show(frame)
	if next(frame.args) then
		error("This module function does not require any parameters.")
	end
	
	local ugsub, decompose, U = mw.ustring.gsub, mw.ustring.toNFD, mw.ustring.char
	local macron = U(0x304)
	local breve = U(0x306)
	
	local function make_entry_name(text)
		text = ugsub(decompose(text), "[" .. macron .. breve .. "]", "")
		return text
	end
	
	local title = decompose(mw.title.getCurrentTitle().text)
	
	local function link_or_not(text)
		if text:find("[[", 1, true) then
			return text:gsub("%[%[([^%]]+)%]%]", link_or_not)
		else
			local entry_name = make_entry_name(text)
			if entry_name ~= title then
				return '[[' .. entry_name .. '#Latin|' .. text .. ']]'
			else
				return '<strong class="selflink">' .. text .. '</strong>'
			end
		end
	end
	
	local function tag(text)
		return '<span lang="la">' .. link_or_not(text) .. '</span>'
	end
	
	return (template:gsub('{{{([^}]+)}}}', tag))
end

return export