Модуль:Не переведено: различия между версиями

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
[отпатрулированная версия][отпатрулированная версия]
Содержимое удалено Содержимое добавлено
~
~
Строка 86: Строка 86:
local lang = args[i - 1]
local lang = args[i - 1]
local iw_title = args[i]
local iw_title = args[i]
local iw_text = args[i + 1]
if is_empty(iw_title) then
if is_empty(iw_title) then
iw_title = title
iw_title = title
end
if is_empty(iw_text) then
iw_text = iw_title
end
end
if is_empty(lang) then
if is_empty(lang) then
Строка 100: Строка 104:
local iw_link
local iw_link
if show_original then
if show_original then
iw_link = wikilink(lang, iw_title, iw_title)
iw_link = wikilink(lang, iw_title, iw_text)
else
else
iw_link = wikilink(lang, iw_title, languages[lang][1])
iw_link = wikilink(lang, iw_title, languages[lang][1])
Строка 107: Строка 111:
['link'] = iw_link,
['link'] = iw_link,
['lang'] = lang,
['lang'] = lang,
['title'] = iw_title
['text'] = iw_text
}
}
if show_original then
i = i + 2
i = i + 3
else
i = i + 2
end
j = j + 1
j = j + 1
end
end
Строка 126: Строка 134:
local lang = iw_list[i]['lang']
local lang = iw_list[i]['lang']
local lang_link = wikilink('ru', languages[lang][2], languages[lang][1])
local lang_link = wikilink('ru', languages[lang][2], languages[lang][1])
local iw_title = iw_list[i]['title']
local iw_text = iw_list[i]['text']
local iw_link = iw_list[i]['link']
local iw_link = iw_list[i]['link']
if mw.isSubsting() or exists then
if mw.isSubsting() or exists then
if show_original then
if show_original then
post_text_list[i] = string.format('%s %s', lang_link, italic(iw_title))
post_text_list[i] = string.format('%s %s', lang_link, italic(iw_text))
end
end
elseif show_original then
elseif show_original then

Версия от 19:10, 11 декабря 2017

Документация

Служит для работы шаблонов {{не переведено}}, {{не переведено 2}}, {{не переведено 3}}, {{не переведено 4}} и {{не переведено 5}}.

См. также: Модуль:Не переведено/песочница (сравнить) и Шаблон:Не переведено/тесты.

TODO

  • внешний вид нп3
  • возможно, что-то с nil из [1]
local getArgs = require('Module:Arguments').getArgs
local p = {}

local function is_empty(param)
	return param == nil or param == ''
end

local function wikilink(lang, title, text)
	if is_empty(text) then 
		text = title
	end
	if lang ~= 'ru' then 
		title = string.format(':%s:%s', lang, title)
	end
	return string.format('[[%s|%s]]', title, text)
end

local function italic(s)
	return tostring(
		mw.html.create('span')
		:css('font-style', 'italic')
		:wikitext(s)
	)
end

function p.main(frame)
	local yesno = require('Module:Yesno')
	local args = getArgs(frame)
	local languages = mw.loadData('Module:Languages/data')
	local error = require('Module:Error').error
	
	local title
	local text
	
	local addition = args['a']
	local show_original = yesno(args['o']) or addition ~= nil
	local leave = yesno(args['l'])
	
	local categories = ''
	local nocat = yesno(args['nocat'])
	local allow_cat = mw.title.getCurrentTitle().namespace == 0 and not nocat
	local orphan_categories = {
		['error'] = '[[Категория:Википедия:Статьи с некорректно заполненным шаблоном Не переведено]]',
		['outdated'] = '[[Категория:Википедия:Статьи с неактуальным шаблоном Не переведено]]',
		['redirect'] = '[[Категория:Википедия:Запросы на замену перенаправлений переводами]]'
	}
	
	if is_empty(args[1]) and not args['есть']:match('^:[a-z-]+:') then
		if allow_cat then 
			categories = categories .. orphan_categories['error']
		end
		return error{'не указано название статьи'} .. categories
	end

	if not is_empty(args['есть']) or args[1]:match('^:[a-z-]+:') then
		local temp
		if is_empty(args['есть']) then 
			temp = args[1]
		else
			temp = args['есть']
		end
		args[1] = args['надо'] or args['нужно'] or args[2] or ''
		args[2] = args['текст'] or args[3]
		args[3] = mw.ustring.sub(temp, 2, mw.ustring.find(temp, ':', 2, true) - 1)
		args[4] = mw.ustring.sub(temp, mw.ustring.find(temp, ':', 2, true) + 1)
		if is_empty(args[1]) then 
			args[1] = args[4]
		end
	end

	title = args[1]
	text = args[2]
	local exists = mw.title.new(title).exists and not leave
	local ru_link = wikilink('ru', title, text)
	if exists and not mw.isSubsting() then
		ru_link = tostring(
			mw.html.create('span')
			:css('background', '#FFFF00')
			:wikitext(ru_link)
		)
	end

	local iw_list = {}
	local i, j = 4, 1
	while args[i] or args[i - 1] or i <= 4 do
		local lang = args[i - 1]
		local iw_title = args[i]
		local iw_text = args[i + 1]
		if is_empty(iw_title) then
			iw_title = title
		end
		if is_empty(iw_text) then
			iw_text = iw_title
		end
		if is_empty(lang) then
			lang = 'en'
		end
		if languages[lang] == nil then
			if allow_cat then 
				categories = categories .. orphan_categories['error']
			end
			return error{'некорректный ISO-код языка'} .. categories
		end
		local iw_link
		if show_original then
			iw_link = wikilink(lang, iw_title, iw_text)
		else
			iw_link = wikilink(lang, iw_title, languages[lang][1])
		end
		iw_list[j] = {
			['link'] = iw_link,
			['lang'] = lang,
			['text'] = iw_text
		}
		if show_original then
			i = i + 3
		else
			i = i + 2
		end
		j = j + 1
	end
	
	if yesno(leave) and mw.title.new(title).isRedirect and allow_cat then
		categories = categories .. orphan_categories['redirect']
	end
	if exists and allow_cat then
		categories = categories .. orphan_categories['outdated']
	end
	
	local post_text = ''
	local post_text_list = {}
	local i = 1
	while iw_list[i] do
		local lang = iw_list[i]['lang']
		local lang_link = wikilink('ru', languages[lang][2], languages[lang][1])
		local iw_text = iw_list[i]['text']
		local iw_link = iw_list[i]['link']
		if mw.isSubsting() or exists then	
			if show_original then
				post_text_list[i] = string.format('%s&nbsp;%s', lang_link, italic(iw_text))
			end
		elseif show_original then
			post_text_list[i] = string.format('%s&nbsp;%s', lang_link, italic(iw_link))
		else
			post_text_list[i] = iw_link
		end
		i = i + 1
	end
	if not is_empty(addition) then
		addition = '; ' .. addition
	else 
		addition = ''
	end
	if next(post_text_list) ~= nil then
		post_text = ' (' .. table.concat(post_text_list, ', ') .. addition .. ')'
		if not show_original then
			post_text = tostring(
				mw.html.create('span')
				:addClass('noprint')
				:css('font-size', '85%')
				:wikitext(post_text)
			)
		end
	end
	
	local exist_message = ''
	if exists then
		exist_message = tostring(
			mw.html.create('sup')
			:addClass('noprint')
			:wikitext('[' .. italic('[[Шаблон:Не переведено#Действия после появления перевода|убрать шаблон]]') .. ']')
		)
	end
	
	local result
	result = ru_link .. post_text
	if not mw.isSubsting() then
		result = result .. exist_message .. categories
	end
	
	return result
end

return p