Відмінності між версіями «Модуль:Wikidata1»

нема опису редагування
}
 
--require("Module:i18n").loadI18n("Module:Wikidata/i18n", i18n)
-- Credit to http://stackoverflow.com/a/1283608/2644759
-- got idea from [[:w:Module:Wd]]
-- cc-by-sa 3.0
local module_title; if ... == nil then
local function tableMerge(t1, t2)
module_title = mw.getCurrentFrame():getTitle()
for k,v in pairs(t2) do
else
if type(v) == "table" then
module_title = ...
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
require('Module:i18n').loadI18n(module_title..'/i18n', i18n)
 
local function loadI18n()
local exist, res = pcall(require, "Module:Wikidata/i18n")
if exist and next(res) ~= nil then
tableMerge(i18n, res.i18n)
end
end
 
loadI18n()
 
-- this function needs to be internationalised along with the above:
return '<span class="error">' .. (i18n.errors[code] or code) .. '</span>'
end
local function parseDateFormat(f, timestamp, addon, prefix_addon, addon_sep)
 
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(f, 'Y', true)
for kidx,v f_part in pairs(t2f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
if addon ~= "" and prefix_addon then
return addon .. addon_sep .. tstr
elseif addon ~= "" then
return tstr .. addon_sep .. addon
else
return t1tstr
end
end
local function parseDateValue(timestamp, date_format, date_addon)
local prefix_addon = i18n["datetime"]["prefix-addon"]
timestamp = '+' .. string.sub(timestamp, 2)
addon = date_addon
end
local function d(f)
local year_suffix
local tstr = ""
local lang_obj = mw.language.new(wiki.langcode)
local f_parts = mw.text.split(f, 'Y', true)
for idx, f_part in pairs(f_parts) do
year_suffix = ''
if string.match(f_part, "x[mijkot]$") then
-- for non-Gregorian year
f_part = f_part .. 'Y'
elseif idx < #f_parts then
-- supress leading zeros in year
year_suffix = lang_obj:formatDate('Y', timestamp)
year_suffix = string.gsub(year_suffix, '^0+', '', 1)
end
tstr = tstr .. lang_obj:formatDate(f_part, timestamp) .. year_suffix
end
if addon ~= "" and prefix_addon then
return addon .. addon_sep .. tstr
elseif addon ~= "" then
return tstr .. addon_sep .. addon
else
return tstr
end
end
local _date_format = i18n["datetime"]["format"][date_format]
if _date_format ~= nil then
return dparseDateFormat(_date_format, timestamp, addon, prefix_addon, addon_sep)
else
return printError("unknown-datetime-format")
250

редагувань