Jump to content

Module:Alternative forms

ពីWiktionary

Documentation for this module may be created at Module:Alternative forms/doc

local export = {}
local m_link = require('Module:links')
local m_languages = require("Module:languages")

function export.create(frame)
	local args = frame:getParent().args
	local term = args[2]
	local lang = m_languages.getLanguageByCode(args[1])
	local lang_code = lang:getCode()
	
	local link = m_link.full_link(term, nil, lang, nil, nil, nil, {})
	
	local dialect_page = frame:getTitle().fullText .. '/dialects/' .. lang_code
	local has_dialect_info, dialect_info = pcall(require, dialect_page)
	if not has_dialect_info then
		-- the variable contains an error message now; get rid of it
		dialect_info = nil
	end
	local dialects = {}
	local which_arg = ''
	local current_dialect = ''
	local current_info = {}
	local dialect_display = ''
	local dialect_link = ''
	local dialect_final = ''

	for i = 1, 20 do
		which_arg = 'dial' .. i
		if which_arg == 'dial1' then which_arg = 'dial' end
		if args[which_arg] then
			current_dialect = args[which_arg]
			if dialect_info and dialect_info.data[current_dialect] then
				current_info = dialect_info.data[current_dialect]
				dialect_link = current_info.link
				dialect_display = current_info.display or current_dialect
				if dialect_link then
					dialect_final = '[[w:'..dialect_link..'|'..dialect_display..']]'
				else
					dialect_final = dialect_display
				end
			else
				dialect_final = current_dialect
			end
			table.insert(dialects, dialect_final)
		end
	end

	if #dialects > 0 then
		return link .. ' - ' .. table.concat(dialects, ", ")
	else
		return link
	end
end

return export