Modul:Wikidata/lib
Vzhled
require "Modul:No globals"
local p = {
common = require "Modul:Functions",
props = {
begin = { 'P569', 'P580' },
ending = { 'P570', 'P582' },
lang = { 'P364', 'P407' },
point = { 'P571', 'P577', 'P585' },
}
}
local i18n = mw.loadData("Modul:Wikidata/i18n")
function p.isOptionTrue(options, key)
if options[key] then
if tostring(options[key]) == 'true' or tostring(options[key]) == 'yes' or tostring(options[key]) == '1' then
return true
end
end
return false
end
function p.textToTable(something, options)
if type(something) == "table" then
return p.common.cleanArgs(something)
end
local options = options or {}
local split_pattern = options.split_pattern or "%s*,%s*"
if p.isOptionTrue(options, 'upper') then
something = mw.ustring.upper(something)
elseif p.isOptionTrue(options, 'upperfirst') then
something = p.common.stringToUpper(something)
end
something = mw.text.split(something, split_pattern)
return p.common.cleanArgs(something)
end
function p.getEntityIdFromValue(value)
local entityType = value['entity-type']
if entityType == 'item' then
return 'Q' .. value['numeric-id']
elseif entityType == 'property' then
return 'P' .. value['numeric-id']
else
return error(p.formatError('unknown-entity-type', entityType))
end
end
function p.category(key, ...)
local Category = require 'Modul:Kategorie'
local title = mw.title.getCurrentTitle()
return Category.makeCategory(mw.ustring.format(i18n.categories[key], ...), '0,14', title.text)
end
function p.formatError(key, ...)
return mw.ustring.format(i18n.errors[key], ...)
end
return p