PageSourceSearch

https://elticon.ru/google-translate/js/google-translate.js

js elticon.ru collected 2026-10-06 05:53:13 UTC 4,178 bytes, 109 lines download raw bytes

1/*!***************************************************
2 * google-translate.js v1.0.5
3 * https://Get-Web.Site/
4 * author: Vitalii P.
5 *****************************************************/
6
7const googleTranslateConfig = {
8	/* Original language */
9	lang: "ru",
10
11	/* The language we translate into on the first visit*/
12	/* Язык, на который переводим при первом посещении */
13	/* langFirstVisit: 'en', */
14
15	/* Если скрипт не работает или работает неправильно, раскомментируйте и укажите основной домен в свойстве domain */
16	/* If the script does not work or does not work correctly, uncomment and specify the main domain in the domain property */
17	/* domain: "Get-Web.Site" */
18};
19
20$(function () {
21	/* Подключаем виджет google translate */
22	/* Connecting the google translate widget */
23	let script = document.createElement("script");
24	script.src = `//translate.google.com/translate_a/element.js?cb=TranslateWidgetIsLoaded`;
25	document.getElementsByTagName("head")[0].appendChild(script);
26});
27
28function TranslateWidgetIsLoaded() {
29	TranslateInit(googleTranslateConfig);
30}
31
32function TranslateInit(config) {
33	if (config.langFirstVisit && !$.cookie("googtrans")) {
34		/* Если установлен язык перевода для первого посещения и куки не назначены */
35		/* If the translation language is installed for the first visit and cookies are not assigned */
36		TranslateCookieHandler("/auto/" + config.langFirstVisit);
37	}
38
39	let code = TranslateGetCode(config);
40
41	TranslateHtmlHandler(code);
42
43	if (code == config.lang) {
44		/* Если язык по умолчанию, совпадает с языком на который переводим, то очищаем куки */
45		/* If the default language is the same as the language we are translating into, then we clear the cookies */
46		TranslateCookieHandler(null, config.domain);
47	}
48
49	/* Инициализируем виджет с языком по умолчанию */
50	/* Initialize the widget with the default language */
51	new google.translate.TranslateElement({
52		pageLanguage: config.lang,
53		multilanguagePage: true, // Your page contains content in more than one languages
54	});
55
56	/* Вешаем событие  клик на флаги */
57	/* Assigning a handler to the flags */
58	$("[data-google-lang]").click(function () {
59		TranslateCookieHandler(
60			"/auto/" + $(this).attr("data-google-lang"),
61			config.domain
62		);
63		/* Перезагружаем страницу */
64		/* Reloading the page */
65		window.location.reload();
66	});
67}
68
69function TranslateGetCode(config) {
70	/* Если куки нет, то передаем дефолтный язык */
71	/* If there are no cookies, then we pass the default language */
72	let lang =
73		$.cookie("googtrans") != undefined && $.cookie("googtrans") != "null"
74			? $.cookie("googtrans")
75			: config.lang;
76	return lang.match(/(?!^\/)[^\/]*$/gm)[0];
77}
78
79function TranslateCookieHandler(val, domain) {
80	/* Записываем куки /язык_который_переводим/язык_на_который_переводим */
81	/* Writing down cookies /language_for_translation/the_language_we_are_translating_into */
82	$.cookie("googtrans", val, {
83		domain: document.domain,
84		path: '/'
85	});
86	$.cookie("googtrans", val, {
87		domain: "." + document.domain,
88		path: '/'
89	});
90
91	if (domain == "undefined") return;
92	/* записываем куки для домена, если он назначен в конфиге */
93	/* Writing down cookies for the domain, if it is assigned in the config */
94	$.cookie("googtrans", val, {
95		domain: domain,
96		path: '/'
97	});
98
99	$.cookie("googtrans", val, {
100		domain: "." + domain,
101		path: '/'
102	});
103}
104
105function TranslateHtmlHandler(code) {
106	/* Получаем язык на который переводим и производим необходимые манипуляции с DOM */
107	/* We get the language to which we translate and produce the necessary manipulations with DOM */
108	$('[data-google-lang="' + code + '"]').addClass("language__img_active");
109}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.