跳转到内容

模組:La-noun/table

維基詞典,自由的多語言詞典
local export = {}

local Array = require 'Module:array'

local function add_forms(wikitable, forms)
	if type(wikitable) ~= 'string' then
		error('Expected string, got ' .. type(wikitable))
	end
	
	wikitable = wikitable:gsub('{{{([^}]+)}}}', forms)
	return wikitable
end

function export.make_table_sg(data)
	local output = Array(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = string.gsub(data.title, '%.', ''), palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! 單數
|-
! [[主格]]
| {{{nom_sg}}}
|-
! [[屬格]]
| {{{gen_sg}}}
|-
! [[與格]]
| {{{dat_sg}}}
|-
! [[賓格]]
| {{{acc_sg}}}
|-
! [[離格]]
| {{{abl_sg}}}
|-
! [[呼格]]
| {{{voc_sg}}}
|-]=]
	if data.forms.loc_sg then
		output:insert [=[

! [[方位格]]
| {{{loc_sg}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom', args = { notes = data.footnotes or '' } })

	return add_forms(output:concat(), data.forms)
end

function export.make_table_pl(data)
	local output = Array(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = string.gsub(data.title, '%.', ''), palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! 複數
|-
! [[主格]]
| {{{nom_pl}}}
|-
! [[屬格]]
| {{{gen_pl}}}
|-
! [[屬格]]
| {{{dat_pl}}}
|-
! [[賓格]]
| {{{acc_pl}}}
|-
! [[離格]]
| {{{abl_pl}}}
|-
! [[呼格]]
| {{{voc_pl}}}
|-
]=]
	if data.forms.loc_pl then
		output:insert [=[

! [[方位格]]
| {{{loc_pl}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom', args = { notes = data.footnotes or '' } })
	
	return add_forms(output:concat(), data.forms)
end

function export.make_table(data)
	local output = Array(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-top', args = { title = string.gsub(data.title, '%.', ''), palette = 'cyan', lang = 'la' } })
	output:insert [=[
! 
! 單數
! 複數
|-
! [[主格]]
| {{{nom_sg}}}
| {{{nom_pl}}}
|-
! [[屬格]]
| {{{gen_sg}}}
| {{{gen_pl}}}
|-
! [[屬格]]
| {{{dat_sg}}}
| {{{dat_pl}}}
|-
! [[賓格]]
| {{{acc_sg}}}
| {{{acc_pl}}}
|-
! [[離格]]
| {{{abl_sg}}}
| {{{abl_pl}}}
|-
! [[呼格]]
| {{{voc_sg}}}
| {{{voc_pl}}}
|-]=]
	if data.forms.loc_sg or data.forms.loc_pl then
		output:insert [=[

! [[方位格]]
| {{{loc_sg}}}
| {{{loc_pl}}}]=]
	end
	output:insert('\n')
	output:insert(mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom', args = { notes = data.footnotes or '' } })
	
	return add_forms(output:concat(), data.forms)
end

return export