Jump to content

Module:I18n/objects

Wikibooks වෙතින්
local wikidata_label = require('Module:Wikidata label')._getLabel
local LookupTable = mw.loadData('Module:I18n/objects/data')

local p = {}

function p.simpleObject(object, lang)
	local wikitext = ''
	local item = LookupTable[string.lower(object)] -- try to find an item in the dictionary
	if item then
	-- if an item was found use it
		wikitext = wikidata_label(item, lang)
	elseif object and object ~= '' then
	-- set maintenance category and fall back to the input string
		wikitext = '[[Category:Unsupported object|' .. object .. ']]' .. object
	end
	return wikitext, item
end

function p._object(object, relObject, lang)
	local relText, relItem, relQs
	local wikitext, mainItem = p.simpleObject(object, lang)
	if relObject and relObject ~= '' then
		relText, relItem = p.simpleObject(relObject, lang)
		wikitext = string.format('%s (%s)', wikitext, relText)
	end
	-- create non-visible language independent marking in QuickStatements-like format
	local qsText = ''
	local qs = ''
	if mainItem then
		if relItem then
			relQs = ',P642,' .. relItem -- property "of" (P642), as a qualifier to P31
		else
			relQs = ''
		end
		qsText = '<div style="display: none;">object_type QS:P31,' .. mainItem .. relQs .. '</div>'
		 -- property "instance of" (P31)
	end
	return wikitext .. qsText
end

function p.object(frame)
	local args = frame.args
	return p._object(args.object, args.relObject, args.lang)
end

return p
"https://si.wikibooks.org/w/index.php?title=Module:I18n/objects&oldid=24448" වෙතින් සම්ප්‍රවේශනය කෙරිණි