Модуль:Не переведено: различия между версиями
Перейти к навигации
Перейти к поиску
(+) |
(~) |
||
Строка 1: | Строка 1: | ||
+ | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
Строка 25: | Строка 26: | ||
function p.main(frame) | function p.main(frame) | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
− | local args = frame | + | local args = getArgs(frame) |
local languages = mw.loadData('Module:Languages/data') | local languages = mw.loadData('Module:Languages/data') | ||
local error = require('Module:Error').error | local error = require('Module:Error').error |
Версия от 19:51, 11 декабря 2017
Для документации этого модуля может быть создана страница Модуль:Не переведено/doc
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]
if is_empty(iw_title) then
iw_title = 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_title)
else
iw_link = wikilink(lang, iw_title, languages[lang][1])
end
iw_list[j] = {
['link'] = iw_link,
['lang'] = lang,
['title'] = iw_title
}
i = i + 2
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_title = iw_list[i]['title']
local iw_link = iw_list[i]['link']
if mw.isSubsting() or exists then
if show_original then
post_text_list[i] = string.format('%s %s', lang_link, italic(iw_title))
end
elseif show_original then
post_text_list[i] = string.format('%s %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