Answer the question
In order to leave comments, you need to log in
What is the script for translating a page from Russian into English?
Previously, there was a jquery plugin for a site that could translate a page on the fly into any language with a single keystroke. I need to implement multilingualism on the site, and such a plugin would come in handy, bearing in mind its ease of connection and minimal labor costs for its (multilingualism) implementation.
As far as I know, Google Translate API has become paid. Support and operation of such a plugin has stopped. There is a kind of analogue of the Bing Translate API. But I need the js script itself. Are there any in nature? Translation should be carried out without going to third-party sites.
Thank you.
Answer the question
In order to leave comments, you need to log in
Making this answer for future generations.
Literally just successfully connected GTApi to the site, I post what and how.
At the time of 010920 GTApi officially ceased to distribute, however, they left the opportunity for already working sites to use it.
(function() {
var d = "text/javascript"
, e = "text/css"
, f = "stylesheet"
, g = "script"
, h = "link"
, k = "head"
, l = "complete"
, m = "UTF-8"
, n = ".";
function p(b) {
var a = document.getElementsByTagName(k)[0];
a || (a = document.body.parentNode.appendChild(document.createElement(k)));
a.appendChild(b)
}
function _loadJs(b) {
var a = document.createElement(g);
a.type = d;
a.charset = m;
a.src = b;
p(a)
}
function _loadCss(b) {
var a = document.createElement(h);
a.type = e;
a.rel = f;
a.charset = m;
a.href = b;
p(a)
}
function _isNS(b) {
b = b.split(n);
for (var a = window, c = 0; c < b.length; ++c)
if (!(a = a[b[c]]))
return !1;
return !0
}
function _setupNS(b) {
b = b.split(n);
for (var a = window, c = 0; c < b.length; ++c)
a.hasOwnProperty ? a.hasOwnProperty(b[c]) ? a = a[b[c]] : a = a[b[c]] = {} : a = a[b[c]] || (a[b[c]] = {});
return a
}
window.addEventListener && "undefined" == typeof document.readyState && window.addEventListener("DOMContentLoaded", function() {
document.readyState = l
}, !1);
if (_isNS('google.translate.Element')) {
return
}
(function() {
var c = _setupNS('google.translate._const');
c._cl = 'ru';
c._cuc = 'googleTranslateElementInit';
c._cac = '';
c._cam = '';
c._ctkk = eval('((function(){var a\x3d71640675;var b\x3d-12312877;return 406476+\x27.\x27+(a+b)})())');
var h = 'translate.googleapis.com';
var s = (true ? 'https' : window.location.protocol == 'https:' ? 'https' : 'http') + '://';
var b = s + h;
c._pah = h;
c._pas = s;
c._pbi = b + '/translate_static/img/te_bk.gif';
c._pci = b + '/translate_static/img/te_ctrl3.gif';
c._pli = b + '/translate_static/img/loading.gif';
c._plla = h + '/translate_a/l';
c._pmi = b + '/translate_static/img/mini_google.png';
c._ps = b + '/translate_static/css/translateelement.css';
c._puh = 'translate.google.com';
_loadCss(c._ps);
_loadJs(b + '/translate_static/js/element/main_ru.js');
})();
})();
var cookie = get_cookie( 'googtrans' );
if (cookie == null) {
$('.translate .lang_ru').addClass('active')
}else{
var get_cook = cookie.split('/')[2];
$('.translate .lang_'+get_cook).addClass('active');
}
function doGTranslate(lang_pair) {
$('.translate li').click(function () {
$('.translate li').removeClass('active');
$(this).addClass('active');
return false;
});
if (lang_pair.value)
lang_pair = lang_pair.value;
// if (lang_pair == '')
// return;
var lang = lang_pair.split('|')[1];
var teCombo;
var sel = document.getElementsByTagName('select');
for (var i = 0; i < sel.length; i++)
if (sel[i].className == 'goog-te-combo')
teCombo = sel[i];
if (document.getElementById('google_translate_element') == null || document.getElementById('google_translate_element').innerHTML.length == 0 || teCombo.length == 0 || teCombo.innerHTML.length == 0) {
setTimeout(function() {
doGTranslate(lang_pair)
}
, 500);
}
else {
teCombo.value = lang;
GTranslateFireEvent(teCombo, 'change')
}
};
function GTranslateFireEvent(element, event) {
try {
if (document.createEventObject) {
var evt = document.createEventObject();
element.fireEvent('on' + event, evt)
}
else {
var evt = document.createEvent('HTMLEvents');
evt.initEvent(event, true, true);
element.dispatchEvent(evt)
}
}
catch (e) {}
};
function get_cookie ( cookie_name ) {
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
if ( results )
return ( unescape ( results[2] ) );
else
return null;
}
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'ru'
},'google_translate_element');
};
<script src=".../Код_выше.js"></script>
<style type="text/css">
body { top: 0px !important; } /* Убираем отступ который выставляет скрипт */
.skiptranslate { display: none !important; } /* Скрываем гугловский навбар с выбором языка */
</style>
<div id="google_translate_element"></div>
<ul class="translate">
<li class="">
<a href="#" onclick="doGTranslate('ru|en');"> <!-- Переводим сайт с русского на английский -->
<img height="20" width="30"
alt="Флаг страны 1"
src="Папка с флагами\флаг1.png">
<span>
Язык 1
</span>
</a>
</li>
</ul>
<div id="languages-boxes">
@php
$langFrom = 'en'; # С какого языка переводим. (Исходный язык сайта)
$langFlagsImgFolder = 'public\\Flags'; # Путь к папке с флагами.
$langsSettings = array(
[ 'GTLangName' => 'en', # Имя языка в GoogleTranslate
'img-alt' => 'Eng', # Alt для флага
'image-flag-name' => 'gb', # Имя файла с флагом. ...\000.png
'text' => 'English', ], # Подпись рядом с флагом
[ 'GTLangName' => 'fr',
'img-alt' => 'Franc',
'image-flag-name' => 'fr',
'text' => 'French', ],
[ 'GTLangName' => 'de',
'img-alt' => 'Germ',
'image-flag-name' => 'de',
'text' => 'German', ],
[ 'GTLangName' => 'it',
'img-alt' => 'Ital',
'image-flag-name' => 'it',
'text' => 'Italian', ],
[ 'GTLangName' => 'ru',
'img-alt' => 'Rus',
'image-flag-name' => 'ru',
'text' => 'Russian.', ],
);
@endphp
{{-- Тут любой внешний вид верстки --}}
<ul class="translate">
@foreach( $langsSettings as $oneLang )
<li>
<a href="#" onclick="doGTranslate('{{$langFrom}}|{{$oneLang['GTLangName']}}');">
<img height="20" width="30"
alt="{{$oneLang['img-alt']}}"
src="{{$langFlagsImgFolder}}\{{$oneLang['image-flag-name']}}.png">
<span>
{{$oneLang['text']}}
</span>
</a>
</li>
@endforeach
</ul>
</div>
<body style="ваш стиль">
I haven’t heard about GTApi being paid, at least they don’t have any applications for this:
translate.google.com/manager/website/add?hl=en
you do the setup, you get the code, nothing complicated...
google translate allows you to do this
sustec.ru (look in the footer)
minskstay.by my implementation is in the basement while it works. we do not determine the language affiliation, by default the choice of language was during authorization, but it was refused, although it was not required at all. Therefore, only the translator remained in the basement.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question