Модул:Wd/i18n

От Уикицитат

Документация за този модул може да бъде създадена на Модул:Wd/i18n/doc

-- The values and functions in this submodule should be localized per wiki.

-- load submodule "aliasesP" that lives next to this submodule
local aliasesP = mw.loadData((...):sub(1, (...):match('^.*()/') - 1).."/aliasesP")

local p = {
	["errors"] = {
		["unknown-data-type"]          = 'Неизвестен или неподдържан тип данни "$1".',
		["missing-required-parameter"] = 'Не са дефинирани задължителни параметри, изисква се поне един',
		["extra-required-parameter"]   = 'Параметър "$1" трябва да бъде дефиниран като незадължителен',
		["no-function-specified"]      = 'Трябва да бъде посочена функция за извикване',  -- equal to the standard module error message
		["main-called-twice"]          = 'Функцията "main" не може да бъде извикана два пъти',
		["no-such-function"]           = 'Функцията "$1" не съществува'  -- equal to the standard module error message
	},
	["info"] = {
		["edit-on-wikidata"] = 'Редактиране в Уикиданни'
	},
	["numeric"] = {
		["decimal-mark"] = ',',
		["delimiter"]    = ' '
	},
	["datetime"] = {
		["prefixes"] = {
			["decade-period"] = ''
		},
		["suffixes"] = {
			["decade-period"] = '-те',
			["millennium"]    = ' хилядолетие',
			["century"]       = ' век',
			["million-years"] = ' милиони години',
			["billion-years"] = ' милиарди години',
			["year"]          = ' г.',
			["years"]         = ' години'
		},
		["julian-calendar"] = 'Приемане на григорианския календар',  -- linked page title
		["julian"]          = 'стар стил',
		["BCE"]             = 'пр.н.е.',
		["CE"]              = 'сл.н.е.',
		["common-era"]      = 'Нова Ера'  -- linked page title
	},
	["coord"] = {
		["latitude-north"] = "N",
		["latitude-south"] = "S",
		["longitude-east"] = "E",
		["longitude-west"] = "W",
		["degrees"]        = "°",
		["minutes"]        = "'",
		["seconds"]        = '"',
		["separator"]      = ", "
	},
	["values"] = {
		["unknown"] = "неизвестна",
		["none"]    = "няма"
	},
	["cite"] = {
		["version"] = "2",  -- increase this each time the below parameters are changed to avoid conflict errors
		["web"] = {
			-- <= left side: all allowed reference properties for *web page sources* per https://www.wikidata.org/wiki/Help:Sources
			-- => right side: corresponding parameter names in (equivalent of) [[:en:Template:Cite web]] (if non-existent, keep empty i.e. "")
			[aliasesP.statedIn]             = "work",
			[aliasesP.referenceURL]         = "url",
			[aliasesP.publicationDate]      = "date",
			[aliasesP.retrieved]            = "accessdate",
			[aliasesP.title]                = "title",
			[aliasesP.archiveURL]           = "archiveurl",
			[aliasesP.archiveDate]          = "archivedate",
			[aliasesP.language]             = "lang",
			[aliasesP.author]               = "author",  -- existence of author1, author2, author3, etc. is assumed
			[aliasesP.publisher]            = "publisher",
			[aliasesP.quote]                = "quote",
			[aliasesP.pages]                = "pages"  -- extra option
		},
		["q"] = {
			-- <= left side: all allowed reference properties for *sources other than web pages* per https://www.wikidata.org/wiki/Help:Sources
			-- => right side: corresponding parameter names in (equivalent of) [[:en:Template:Cite Q]] (if non-existent, keep empty i.e. "")
			[aliasesP.statedIn]                = "1",
			[aliasesP.pages]                   = "pages",
			[aliasesP.column]                  = "at",
			[aliasesP.chapter]                 = "chapter",
			[aliasesP.sectionVerseOrParagraph] = "section",
			["external-id"]                    = "id",  -- used for any type of database property ID
			[aliasesP.title]                   = "title",
			[aliasesP.publicationDate]         = "date",
			[aliasesP.retrieved]               = "access-date"
		}
	}
}

function p.getOrdinalSuffix(num, gen)
	local gLetter = 'и'
	
	if gen == p['datetime']['suffixes']['millennium'] then
		gLetter = 'o'
	end
	
	if tostring(num):sub(-2,-2) == '1' then
		return '-' .. gLetter	-- 10th, 11th, 12th, 13th, ... 19th
	end
	
	num = tostring(num):sub(-1)
	
	if num == '1' then
		return '-в' .. gLetter
	elseif num == '2' then
		return '-р' .. gLetter
	elseif num == '3' or num == '4' then
		return '-т' .. gLetter
	else
		return '-' .. gLetter
	end
end

function p.addDelimiters(n)
	local left, num, right = string.match(n, "^([^%d]*%d)(%d*)(.-)$")
	local dec, num2, num3, rem = string.match(right, "^([,%.])(%d%d)(%d*)([^%d]*)$")
	
	if dec and num2 and num3 and rem then
		num3 = '0.' .. num3
		if tonumber(num3) >= 0.5 then
			num2 = num2 + 1
		end
		right = dec .. num2 .. rem
	end
	
	if (left and num and right) and (#num > 3) then
		return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. p['numeric']['delimiter']):reverse()) .. right
	elseif left and num and right then
		return left .. num .. right
	else
		return n
	end
end

function p.formatMultilanguageText(text, lang, code)
	if text and lang and lang ~= code then
		local dir = mw.language.new(lang):isRTL() and 'rtl' or 'ltr'
		local attr = {['dir'] = dir, ['lang'] = lang}
		return mw.text.tag('span', attr, text)
	else
		return nil
	end
end

return p