Изменения

Перейти к навигации Перейти к поиску
обновление для перевода всех нпN на единый модуль, см. ВП:ФТ#Общий модуль для шаблонов Не переведено и http://web.archive.org/web/20201019200559/https://ru.wikipedia.org/wiki/Шаблон:Не_переведено/тесты
Строка 20: Строка 20:  
)
 
)
 
end
 
end
if not is_empty(text) then
+
if not is_empty(text) and text ~= title then
 
title = title .. '|' .. text
 
title = title .. '|' .. text
 
end
 
end
Строка 41: Строка 41:  
local prepositional = require('Module:Languages')._transform_lang
 
local prepositional = require('Module:Languages')._transform_lang
   −
local leave_always = yesno(args['l'])
  −
local leave_if_redirect = yesno(args['r'])
  −
   
local categories = ''
 
local categories = ''
 
local nocat = yesno(args['nocat'])
 
local nocat = yesno(args['nocat'])
Строка 52: Строка 49:  
['redirect'] = '[[Категория:Википедия:Запросы на замену перенаправлений переводами]]'
 
['redirect'] = '[[Категория:Википедия:Запросы на замену перенаправлений переводами]]'
 
}
 
}
+
local mode = tonumber(args['mode'])
if is_empty(args[1]) then
+
 
if allow_cat then
+
local title = args[1]
categories = categories .. orphan_categories['error']
+
local text = args[2]
end
+
local lang = args[3]
return error{'не указано название статьи'} .. categories
+
local iw_title = args[4]
end
+
local iw_text = args[5]
    
if args[1]:match('^:[a-z-]+:') then
 
if args[1]:match('^:[a-z-]+:') then
 
if allow_cat then
 
if allow_cat then
if yesno(args['o']) then
+
categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено»]]'
categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено 2»]]'
  −
else
  −
categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено»]]'
  −
end
   
end
 
end
 
return error{'шаблон не поддерживает такой синтаксис'} .. categories
 
return error{'шаблон не поддерживает такой синтаксис'} .. categories
 
end
 
end
 
+
local ru_page = mw.title.new(args[1])
+
if mw.isSubsting() and mode ~= 2 then
if ru_page == nil then
+
return wikilink(title, text)
 +
end
 +
 +
if is_empty(title) then
 
if allow_cat then
 
if allow_cat then
 
categories = categories .. orphan_categories['error']
 
categories = categories .. orphan_categories['error']
 
end
 
end
return error{'некорректные символы в названии статьи'} .. categories
+
return error{'не указано название статьи'} .. categories
end
  −
if leave_if_redirect and not ru_page.isRedirect then
  −
leave_if_redirect = false
  −
end
  −
local exists = ru_page.exists and not ( leave_always or leave_if_redirect )
  −
if leave_if_redirect and allow_cat then
  −
categories = categories .. orphan_categories['redirect']
   
end
 
end
+
if is_empty(text) then
local title = args[1]
+
text = title
local text = args[2]
  −
local ru_link = wikilink(title, text)
  −
if exists and not mw.isSubsting() then
  −
ru_link = tostring(
  −
mw.html.create('span')
  −
:css('background', '#ffff00')
  −
:wikitext(ru_link)
  −
)
   
end
 
end
  −
local post_link = ''
  −
local addition = args['a']
  −
local show_originals = yesno(args['o']) or addition ~= nil
  −
local wikidata_link = ''
  −
  −
local lang = args[3]
  −
local iw_title = args[4]
  −
local iw_text = args[5]
   
if is_empty(lang) then
 
if is_empty(lang) then
 
lang = 'en'
 
lang = 'en'
 
end
 
end
 +
local orig_iw_title = iw_title
 
if is_empty(iw_title) then
 
if is_empty(iw_title) then
 
iw_title = title
 
iw_title = title
Строка 113: Строка 86:  
if is_empty(iw_text) then
 
if is_empty(iw_text) then
 
iw_text = iw_title
 
iw_text = iw_title
 +
end
 +
 +
local ru_page = mw.title.new(title)
 +
if ru_page == nil then
 +
if allow_cat then
 +
categories = categories .. orphan_categories['error']
 +
end
 +
return error{'некорректные символы в названии статьи'} .. categories
 
end
 
end
 
 
Строка 123: Строка 104:  
end
 
end
 
 
local show_original = show_originals and lang ~= 'd'
+
local leave_always = yesno(args['l']) or yesno(args['leave'])
 +
local leave_if_redirect = yesno(args['r'])
 +
if leave_if_redirect and not ru_page.isRedirect then
 +
leave_if_redirect = false
 +
end
 +
local exists = ru_page.exists and not ( leave_always or leave_if_redirect )
 +
if leave_if_redirect and allow_cat then
 +
categories = categories .. orphan_categories['redirect']
 +
end
 +
 +
local iw_tooltip
 +
local ucfirst_title = mw.getContentLanguage():ucfirst(title)
 +
if lang == 'd' then
 +
if mode == 1 or mode == 2 then
 +
iw_tooltip = string.format('Элемент статьи «%s» в Викиданных', ucfirst_title)
 +
elseif mode == 5 then
 +
iw_tooltip = string.format('Страница статьи «%s» в Викиданных', ucfirst_title)
 +
iw_title = iw_title .. '#sitelinks-wikipedia' -- осторожно, может сломать что-то
 +
end
 +
else
 +
if mode == 1 or mode == 2 then
 +
iw_tooltip = string.format('Версия статьи «%s» на %s', ucfirst_title, prepositional(lang))
 +
elseif mode == 4 then
 +
iw_tooltip = string.format('Эквивалент статьи «%s» на %s', ucfirst_title, prepositional(lang))
 +
elseif mode == 5 then
 +
local pref
 +
if is_empty(orig_iw_title) then
 +
pref = 'Версия статьи'
 +
else
 +
pref = string.format('%s — версия статьи', iw_title)
 +
end
 +
iw_tooltip = string.format('%s «%s» на %s', pref, ucfirst_title, prepositional(lang))
 +
end
 +
end
 +
 
 +
-- форматирование первой части - основной ссылки
 +
local main_text
 +
if exists or mode == 1 or mode == 2 or mode == 5 then
 +
if mode == 5 and ru_page.isRedirect then
 +
main_text = string.format('[%s %s]', tostring(mw.uri.fullUrl(title,'redirect=no')), text)
 +
else
 +
main_text = wikilink(title, text)
 +
end
 +
if exists and not mw.isSubsting() and (mode == 1 or mode == 2 or mode == 3) then
 +
main_text = tostring(
 +
mw.html.create('span')
 +
:css('background', '#ffff00')
 +
:wikitext(main_text)
 +
)
 +
end
 +
else
 +
main_text = wikilink(iw_title, text, iw_tooltip, lang)
 +
end
 
 
 +
-- форматирование второй части - языковой метки
 
local lang_text
 
local lang_text
 
local lang_title
 
local lang_title
local lang_link
   
if lang == 'd' then
 
if lang == 'd' then
 
lang_text = 'd'
 
lang_text = 'd'
Строка 138: Строка 171:  
lang_text = languages[lang][1]
 
lang_text = languages[lang][1]
 
lang_title = languages[lang][2]
 
lang_title = languages[lang][2]
lang_link = wikilink(lang_title, lang_text)
   
end
 
end
 
 
local tooltip
  −
local ucfirst_title = mw.getContentLanguage():ucfirst(title)
  −
if lang == 'd' then
  −
tooltip = string.format('Элемент статьи «%s» в Викиданных', ucfirst_title)
  −
else
  −
tooltip = string.format('Версия статьи «%s» на %s', ucfirst_title, prepositional(lang))
  −
end
  −
  −
local iw_link
  −
if show_original then
  −
iw_link = wikilink(iw_title, iw_text, tooltip, lang)
  −
else
  −
iw_link = wikilink(iw_title, lang_text, tooltip, lang)
  −
end
  −
  −
if show_original then
  −
local lang_template = mw.title.new('Template:Lang-' .. lang)
  −
if not lang_template.exists then
  −
if allow_cat then
  −
categories = categories .. '[[Категория:Википедия:Статьи с шаблоном Не переведено 2, использующие несуществующий шаблон lang-XX]]'
  −
end
  −
return error{'не найден шаблон ' .. frame:expandTemplate{ title = 'tl', args = { 'lang-' .. lang } } } .. categories
  −
end
  −
  −
if mw.isSubsting() or exists then
  −
post_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { iw_text } }
  −
else
  −
post_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { iw_link } }
  −
end
  −
elseif not ( mw.isSubsting() or exists ) then
  −
if lang == 'd' then
  −
wikidata_link = iw_link
  −
else
  −
post_link = iw_link
  −
end
  −
end
  −
   
local post_text = ''
 
local post_text = ''
if not is_empty(addition) then
+
if (not exists and not mw.isSubsting()) or mode == 2 or (mode == 5 and ru_page.isRedirect) then
addition = '; ' .. addition
+
if mode == 1 then
else
+
local iw_link = wikilink(iw_title, lang_text, iw_tooltip, lang)
addition = ''
  −
end
  −
if not is_empty(wikidata_link) and not is_empty(post_link) then
  −
wikidata_link = wikidata_link .. '; '
  −
end
  −
  −
if not is_empty(post_link) or not is_empty(wikidata_link) then
  −
post_text = string.format(' (%s%s%s)', wikidata_link, post_link, addition)
  −
if not show_originals or ( is_empty(post_link) and is_empty(addition) ) then --проверить
   
post_text = tostring(
 
post_text = tostring(
 
mw.html.create('span')
 
mw.html.create('span')
Строка 196: Строка 182:  
:css('white-space', 'nowrap')
 
:css('white-space', 'nowrap')
 
:css('font-size', '85%')
 
:css('font-size', '85%')
:wikitext(post_text)
+
:wikitext(' (' .. iw_link .. ')')
 
)
 
)
 +
elseif mode == 2 then
 +
local iw_link = ''
 +
if lang == 'd' then
 +
return error{'шаблон Не переведено 2 не поддерживает Викиданные вместо языка'}
 +
else
 +
local lang_template = mw.title.new('Template:Lang-' .. lang)
 +
if not lang_template.exists then
 +
if allow_cat then
 +
categories = categories .. '[[Категория:Википедия:Статьи с шаблоном Не переведено 2, использующие несуществующий шаблон lang-XX]]'
 +
end
 +
return error{'не найден шаблон ' .. frame:expandTemplate{ title = 'tl', args = { 'lang-' .. lang } } } .. categories
 +
end
 +
 +
if mw.isSubsting() then
 +
iw_link = '{{lang-' .. lang .. '|' .. iw_text .. '}}'
 +
elseif exists then
 +
iw_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { iw_text } }
 +
else
 +
iw_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { wikilink(iw_title, iw_text, iw_tooltip, lang) } }
 +
end
 +
end
 +
 +
local addition = args['text'] or args['текст']
 +
if not is_empty(addition) then
 +
addition = '; ' .. addition
 +
else
 +
addition = ''
 +
end
 +
post_text = ' (' .. iw_link .. addition .. ')'
 +
elseif mode == 3 then
 +
local ref = frame:expandTemplate{ title = 'ref-' .. lang, args = {} }
 +
post_text = '<span style="white-space: nowrap"><span class="noprint" style="font-size:95%; '
 +
.. 'position: relative; top: .4em;">' .. ref .. '</span><span class="link-ru metadata noprint" '
 +
.. 'style="font-size:80%; margin-left:-1.7em; position: relative; top: -.4em;">'
 +
.. wikilink(title, 'русск.') .. '</span></span>'
 +
elseif mode == 4 then
 +
local styles = ''
 +
if lang == 'fr' then
 +
styles = 'margin-right:0.3em;'
 +
elseif lang == 'fi' then
 +
styles = 'margin-right:0.35em;'
 +
elseif lang == 'it' then
 +
styles = 'margin-right:0.5em;'
 +
end
 +
post_text = '<sup class="noprint" style="font-style:normal; margin-left:2px; position:relative; top:-1px;">'
 +
.. wikilink(title, 'ru', 'Статья «' .. title .. '» в русском разделе отсутствует') .. '</sup>'
 +
.. '<sub class="noprint" style="font-style:normal; margin-left:-0.94em; ' .. styles .. '" title="По ссылке доступна статья на '
 +
.. prepositional(lang) .. '">' .. lang .. '</sub>'
 +
else
 +
post_text = '<sup class="iw__note noprint" style="font-style:normal; font-weight:normal;">'
 +
.. string.format('[[:%s:%s|<span class="iw__tooltip" title="%s">[%s]</span>]]</sup>', lang, iw_title, iw_tooltip, lang)
 
end
 
end
 
end
 
end
 
 
 +
-- форматирование третьей части - уведомления о существовании страницы
 
local exist_message = ''
 
local exist_message = ''
 
if exists then
 
if exists then
if allow_cat then
+
if allow_cat and (mode ~= 5 or not ru_page.isRedirect) then
 
categories = categories .. orphan_categories['outdated']
 
categories = categories .. orphan_categories['outdated']
 
end
 
end
local docname = 'Шаблон:Не переведено'
+
if allow_cat and (mode == 5 and ru_page.isRedirect) then
if yesno(args['o']) then
+
categories = categories .. orphan_categories['redirect']
docname = 'Шаблон:Не переведено 2'
   
end
 
end
 
 
exist_message = tostring(
+
if mode == 1 or mode == 2 or mode == 3 then
mw.html.create('sup')
+
local exist_tooltip = ''
:addClass('noprint')
+
if mode == 1 or mode == 2 then
:wikitext(
+
exist_tooltip = 'Пожалуйста, удалите шаблон, заменив «{{не переведено» на  «{{подст:не переведено»'
string.format(
+
else
'&#91;\'\'%s\'\'&#93;',
+
exist_tooltip = 'Пожалуйста, удалите шаблон, заменив «{{не переведено 3» на  «{{подст:переведено 3»'
wikilink(
+
end
docname .. '#Действия после появления страницы',  
+
'убрать шаблон',
+
local docname = 'Шаблон:Не переведено'
'Пожалуйста, удалите шаблон, заменив «{{не переведено» на  «{{подст:не переведено»'
+
if mode == 2 or mode == 3 then
)
+
docname = docname .. ' ' .. mode
 +
end
 +
 +
exist_message = string.format(
 +
'&#91;\'\'%s\'\'&#93;',
 +
wikilink(
 +
docname .. '#Действия после появления страницы',  
 +
'убрать шаблон',
 +
exist_tooltip
 
)
 
)
 
)
 
)
)
+
exist_message = tostring(
 +
mw.html.create('sup')
 +
:addClass('noprint')
 +
:wikitext(exist_message)
 +
)
 +
elseif mode == 4 then
 +
exist_message = '<sup class="noprint">[[Шаблон:Не переведено 4#Действия после появления страницы|'
 +
.. '<span style="background:yellow; color:red; font-style:normal;" title="Пожалуйста, '
 +
.. 'замените шаблон «Не переведено 4» простой вики-ссылкой">\'\'\'?!\'\'\'</span>]]</sup>'
 +
else
 +
if ru_page.isRedirect then
 +
exist_message = '<sup class="iw__notice noprint" style="font-style:normal; font-weight:normal; margin:0 0 0 1px;">'
 +
.. '[[Шаблон:Не переведено 5#Если существует перенаправление|'
 +
.. '<span style="color:red; font-weight:bold;" title="Замените название перенаправления на название статьи либо уберите шаблон «Не переведено 5»">*</span>]]'
 +
.. '</sup>'
 +
else
 +
exist_message = '<sup class="iw__notice noprint">[[Шаблон:Не переведено 5#Если существует статья|'
 +
.. '<span style="color:red; font-style:normal; font-weight:bold;" title="Уберите шаблон «Не переведено 5» из статьи '
 +
.. 'и замените его простой вики-ссылкой">?!</span>]]</sup>'
 +
end
 +
end
 
end
 
end
 
 
 
local result
 
local result
result = ru_link .. post_text
+
result = main_text .. post_text
 
if not mw.isSubsting() then
 
if not mw.isSubsting() then
 
result = result .. exist_message .. categories
 
result = result .. exist_message .. categories
 +
end
 +
if mode == 5 then
 +
local langName = ''
 +
if lang ~= 'd' then
 +
langName = ' data-lang-name="' .. (languages[lang][1] and languages[lang][1] or '???') .. '"'
 +
end
 +
 +
local class = (exists and (ru_page.isRedirect and ' iw--redirect' or ' iw--exists') or '')
 +
result = string.format('<span class="iw%s plainlinks" data-title="%s" data-lang="%s"' .. langName .. '>', class, ucfirst_title, lang)
 +
.. result .. '</span>'
 
end
 
end
 
 
Анонимный участник

Реклама:

Навигация