Module:grc-pronoun table

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

This module generates {{Ancient Greek personal pronouns 1}} and {{Ancient Greek personal pronouns 2}}. Having a module link all the terms in the table is much faster than using a bunch of {{link}} templates.


local export = {}

local U = require("Module:string/char")
local macron = U(0x304)
local breve = U(0x306)

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

local pronoun_table_templates = {
	[1] = -- {{Ancient Greek personal pronouns 1}}
[=[{| class="wikitable" style="font-size: smaller; float: right;"
|+ [[first person]] pronoun <sup>(]=] .. make_edit_link("Module:grc-pronoun table") .. [=[)</sup>
! rowspan="2" | [[case]] !! colspan="2" | [[singular]] !! [[dual]] !! [[plural]]
|-
! [[stressed|str.]] !! [[Appendix:Ancient Greek enclitics|encl.]] !! [[stressed|str.]]  !! [[stressed|str.]] 
|-
! [[nominative]]
| {{{ἐγώ}}} || || {{{νώ}}}, {{{νῶϊ}}} || {{{ἡμεῖς}}}
|-
! [[genitive]]
| {{{ἐμοῦ}}} || {{{μου}}} || {{{νῷν}}} || {{{ἡμῶν}}}
|-
! [[dative]]
| {{{ἐμοί}}} || {{{μοι}}} || {{{νῷν}}} || {{{ἡμῖν}}}
|-
! [[accusative]]
| {{{ἐμέ}}} || {{{με}}} || {{{νώ}}}, {{{νῶϊ}}} || {{{ἡμᾶς}}}
|-
! colspan="5" |
|-
! [[possessive adjective|adjective]]
| {{{ἐμός}}} || || {{{νωΐτερος}}} || {{{ἡμέτερος}}}
|}]=],
	[2] = -- {{Ancient Greek personal pronouns 2}}
[=[{| class="wikitable" style="font-size: smaller; float: right;"
|+ [[second person]] pronoun <sup>(]=] .. make_edit_link("Module:grc-pronoun table") .. [=[)</sup>
! rowspan="2" | [[case]] !! colspan="2" | [[singular]] !! [[dual]] !! [[plural]]
|-
! [[stressed|str.]] !! [[Appendix:Ancient Greek enclitics|encl.]] !! [[stressed|str.]]  !! [[stressed|str.]]
|-
! [[nominative]]
| {{{σύ}}} || || {{{σφώ}}}, {{{σφῶϊ}}} || {{{ῡ̔μεῖς}}}
|-
! [[genitive]]
| {{{σοῦ}}} || {{{σου}}} || {{{σφῷν}}} || {{{ῡ̔μῶν}}}
|-
! [[dative]]
| {{{σοί}}} || {{{σοι}}} || {{{σφῷν}}} || {{{ῡ̔μῖν}}}
|-
! [[accusative]]
| {{{σέ}}} || {{{σε}}} || {{{σφώ}}}, {{{σφῶϊ}}} || {{{ῡ̔μᾶς}}}
|-
! colspan="5" |
|-
! [[possessive adjective|adjective]]
| {{{σός}}} || || {{{σφωΐτερος}}} || {{{ῡ̔μέτερος}}}
|}]=],
}

function export.pronoun_table(frame)
	local person = tonumber(frame.args[1])
	if not person then
		error('Parameter 1 should be a number.')
	end
	local template = pronoun_table_templates[person]
		or error('No template for person ' .. person .. '.')
	
	local ugsub, decompose = mw.ustring.gsub, mw.ustring.toNFD
	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(term)
		local entry_name = make_entry_name(term)
		if entry_name ~= title then
			return '<span class="Polyt" lang="grc">[[' .. entry_name .. '#Ancient Greek|' .. term .. ']]</span>'
		else
			return '<strong class="selflink Polyt" lang="grc">' .. term .. '</strong>'
		end
	end
	
	return (template:gsub('{{{([^}]+)}}}', link))
end

return export