مدیاویکی:Gadget-TranslationAssistant.js: تفاوت میان نسخهها
ظاهر
imported>Ebrahim بدون خلاصۀ ویرایش |
imported>Ebrahim عدم استفاده از mw.Uri |
||
| (۲۴ نسخهٔ میانی ویرایش شده توسط ۲ کاربر نشان داده نشد) | |||
| خط ۱: | خط ۱: | ||
$(function () { | // Translation Assistnant tool, https://fa.wikipedia.org/wiki/MediaWiki:Gadget-TranslationAssistant.js | ||
$.when($.ready, mw.loader.using(['mediawiki.util'])).then(function () { | |||
'use strict'; | 'use strict'; | ||
| خط ۵: | خط ۶: | ||
return; // only for edit mode for now | return; // only for edit mode for now | ||
} | } | ||
var messages = (function () { | |||
var translations = { | |||
ar: { | |||
translationHelper: 'مساعد الترجمة', | |||
pleaseWait: 'انتظر لطفا…', | |||
showWikiCode: 'اظهر كود الويكي' | |||
}, | |||
ckb: { | |||
translationHelper: 'کمک ترجمه', | |||
pleaseWait: 'تکایە ڕاوەستن…', | |||
showWikiCode: 'نیشاندانی ویکیکۆد' | |||
}, | |||
en: { | |||
translationHelper: 'Translation helper', | |||
pleaseWait: 'Wait…', | |||
showWikiCode: 'Show wikicode' | |||
}, | |||
fa: { | |||
translationHelper: 'ترجمهیار', | |||
pleaseWait: 'صبر کنید…', | |||
showWikiCode: 'نمایش ویکیکد' | |||
}, | |||
ur: { | |||
translationHelper: 'معاون مترجم', | |||
pleaseWait: 'انتظار کریں۔۔۔', | |||
showWikiCode: 'ویکی کوڈ دیکھیں' | |||
} | |||
}; | |||
return translations[mw.config.get('wgUserLanguage')] || translations.fa; | |||
}()); | |||
function getTitle(page, source) { | function getTitle(page, source) { | ||
return $.post('// | return $.post('//linkstranslator.toolforge.org/', { | ||
from: mw.config.get('wgDBname'), | from: mw.config.get('wgDBname'), | ||
to: source + 'wiki', | to: source + 'wiki', | ||
| خط ۱۶: | خط ۴۸: | ||
} | } | ||
var enName = new | var enName = new URL(window.location).searchParams.get('enName'); | ||
if (new | if (new URL(window.location).searchParams.get('enName') !== null) { | ||
run(enName); | run(enName, 'en'); | ||
} else { | } else { | ||
$('#t-translationhelper').remove(); | |||
var link = $(mw.util.addPortletLink( | var link = $(mw.util.addPortletLink( | ||
'p-tb', | 'p-tb', | ||
'#', | '#', | ||
messages.translationHelper, | |||
't-translationhelper' | 't-translationhelper' | ||
)); | )); | ||
$('a', link).click(function () { | $('a', link).click(function () { | ||
var source = | $('#translationhelper-helperpage').remove(); | ||
var source = $('#translationhelper-source-langcode').text(); | |||
getTitle(mw.config.get('wgPageName'), source).then(function (title) { | getTitle(mw.config.get('wgPageName'), source).then(function (title) { | ||
run(title, | run(title, source); | ||
}); | }); | ||
}).css('font-weight', 'bold'); | }).css('font-weight', 'bold'); | ||
link.append(' ', $('<span contenteditable id="translationhelper">en</span>').keypress(function (e) { | link.append(' ', $('<span contenteditable id="translationhelper-source-langcode">en</span>').keypress(function (e) { | ||
if (e.which !== 13) return; | if (e.which !== 13) return; | ||
| خط ۴۸: | خط ۸۲: | ||
style: 'width: 100%; height: 100%;' | style: 'width: 100%; height: 100%;' | ||
}); | }); | ||
var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', | var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', readonly: 'readonly' }); | ||
var helperPage = $('<div>').append( | var helperPage = $('<div>', { id: 'translationhelper-helperpage' }).append( | ||
$('<label>').append($('<input>', { type: 'checkbox' }).change(function () { | $('<label>').append($('<input>', { type: 'checkbox' }).change(function () { | ||
if (this.checked) { | if (this.checked) { | ||
enWikiFrame.hide(); | enWikiFrame.hide(); | ||
enWikiSource.show().val( | enWikiSource.show().val(messages.pleaseWait); | ||
$.Deferred().resolve().then(function (result) { | $.Deferred().resolve().then(function (result) { | ||
return window.tofawikipassenwikisource | return window.tofawikipassenwikisource | ||
| خط ۶۷: | خط ۱۰۱: | ||
enWikiSource.hide(); | enWikiSource.hide(); | ||
} | } | ||
}), ' | }), ' ' + messages.showWikiCode), '<br>', enWikiFrame, enWikiSource | ||
); | ); | ||
if ( | if ($(window).width() > 960) { | ||
$('.wikiEditor-ui .wikiEditor-ui-view').css('width', '50%'); | $('.wikiEditor-ui .wikiEditor-ui-view, .ve-init-target-source').css('width', '50%'); | ||
helperPage.attr('style', 'width: 50%; height: 500px; top: 0px; left: 0px; position: absolute;'); | helperPage.attr('style', 'width: 50%; height: 500px; top: 0px; left: 0px; position: absolute;'); | ||
helperPage.insertAfter('.wikiEditor-ui .wikiEditor-ui-view'); | helperPage.insertAfter('.wikiEditor-ui .wikiEditor-ui-view, .ve-init-target-source'); | ||
} else { | } else { | ||
helperPage.attr('style', 'width: 100%; height: 400px;'); | helperPage.attr('style', 'width: 100%; height: 400px;'); | ||
helperPage.insertAfter('#wpTextbox1'); | helperPage.insertAfter('#wpTextbox1, .ve-init-target-source'); | ||
} | } | ||
} | } | ||
نسخهٔ کنونی تا ۵ مارس ۲۰۲۵، ساعت ۰۷:۱۵
// Translation Assistnant tool, https://fa.wikipedia.org/wiki/MediaWiki:Gadget-TranslationAssistant.js
$.when($.ready, mw.loader.using(['mediawiki.util'])).then(function () {
'use strict';
if (['edit', 'submit'].indexOf(mw.config.get('wgAction')) === -1) {
return; // only for edit mode for now
}
var messages = (function () {
var translations = {
ar: {
translationHelper: 'مساعد الترجمة',
pleaseWait: 'انتظر لطفا…',
showWikiCode: 'اظهر كود الويكي'
},
ckb: {
translationHelper: 'کمک ترجمه',
pleaseWait: 'تکایە ڕاوەستن…',
showWikiCode: 'نیشاندانی ویکیکۆد'
},
en: {
translationHelper: 'Translation helper',
pleaseWait: 'Wait…',
showWikiCode: 'Show wikicode'
},
fa: {
translationHelper: 'ترجمهیار',
pleaseWait: 'صبر کنید…',
showWikiCode: 'نمایش ویکیکد'
},
ur: {
translationHelper: 'معاون مترجم',
pleaseWait: 'انتظار کریں۔۔۔',
showWikiCode: 'ویکی کوڈ دیکھیں'
}
};
return translations[mw.config.get('wgUserLanguage')] || translations.fa;
}());
function getTitle(page, source) {
return $.post('//linkstranslator.toolforge.org/', {
from: mw.config.get('wgDBname'),
to: source + 'wiki',
p: page
}).then(function (result) {
return Object.keys(result).map(function (x) { return result[x]; })[0];
});
}
var enName = new URL(window.location).searchParams.get('enName');
if (new URL(window.location).searchParams.get('enName') !== null) {
run(enName, 'en');
} else {
$('#t-translationhelper').remove();
var link = $(mw.util.addPortletLink(
'p-tb',
'#',
messages.translationHelper,
't-translationhelper'
));
$('a', link).click(function () {
$('#translationhelper-helperpage').remove();
var source = $('#translationhelper-source-langcode').text();
getTitle(mw.config.get('wgPageName'), source).then(function (title) {
run(title, source);
});
}).css('font-weight', 'bold');
link.append(' ', $('<span contenteditable id="translationhelper-source-langcode">en</span>').keypress(function (e) {
if (e.which !== 13) return;
$(this).blur();
e.preventDefault();
}).click(function () {
document.execCommand('selectAll', false, null);
}));
}
function run(page, source) {
var enWikiFrame = $('<iframe>', {
src: 'https://' + source + '.wikipedia.org' + mw.util.getUrl(page) + '#tofawikiframe',
style: 'width: 100%; height: 100%;'
});
var enWikiSource = $('<textarea>', { style: 'display: none; width: 100%; height: 100%', dir: 'ltr', readonly: 'readonly' });
var helperPage = $('<div>', { id: 'translationhelper-helperpage' }).append(
$('<label>').append($('<input>', { type: 'checkbox' }).change(function () {
if (this.checked) {
enWikiFrame.hide();
enWikiSource.show().val(messages.pleaseWait);
$.Deferred().resolve().then(function (result) {
return window.tofawikipassenwikisource
? window.tofawikipassenwikisource
: getRawPage(page, source).then(function (result) {
return window.tofawikipassenwikisource = result;
});
}).then(function (result) {
enWikiSource.val(result);
});
} else {
enWikiFrame.show();
enWikiSource.hide();
}
}), ' ' + messages.showWikiCode), '<br>', enWikiFrame, enWikiSource
);
if ($(window).width() > 960) {
$('.wikiEditor-ui .wikiEditor-ui-view, .ve-init-target-source').css('width', '50%');
helperPage.attr('style', 'width: 50%; height: 500px; top: 0px; left: 0px; position: absolute;');
helperPage.insertAfter('.wikiEditor-ui .wikiEditor-ui-view, .ve-init-target-source');
} else {
helperPage.attr('style', 'width: 100%; height: 400px;');
helperPage.insertAfter('#wpTextbox1, .ve-init-target-source');
}
}
function getRawPage(page, source) {
return new mw.Api({ ajax: { url: '//' + source + '.wikipedia.org/w/api.php' } }).get({
action: 'query',
prop: 'revisions',
titles: page,
rvprop: 'content',
format: 'json',
origin: window.location.protocol + '//' + window.location.hostname
}).then(function (data) {
return data.query.pages && !data.query.pages[-1]
? Object.keys(data.query.pages).map(function (x) { return data.query.pages[x]; })[0].revisions[0]['*']
: '';
});
}
});