PageSourceSearch

https://forexsklad.org/google-translate/js/google-translate.js

js forexsklad.org collected 2026-09-26 00:04:25 UTC 6,181 bytes, 151 lines download raw bytes

1/*!***************************************************
2 * google-translate.js v1.0.6
3 * https://Get-Web.Site/
4 * author: Vitalii P.
5 *****************************************************/
6
7
8/* Вы можете перенести данный конфиг в head своего сайта, чтобы динамически конфигурировать значения при помощи данных из CMS */
9/* You can transfer this config to the head of your site to dynamically configure values using data from the CMS */
10
11
12const googleTranslateConfig = {
13	/* Original language */
14	lang: "ru",
15
16	/* Если хотите подписаться на событие "FinishTranslate" (Момент когда скрипт закончил перевод), расскоментируйте и добавьте любое проверочное слово на оригинальном языке */
17	/* If you want to subscribe to the "FinishTranslate" event (The moment when the script finished translating), uncomment and add any test word in the original language */
18	// testWord: "Язык",
19
20	/* The language we translate into on the first visit*/
21	/* Язык, на который переводим при первом посещении */
22	// langFirstVisit: 'en',
23
24	/* Если скрипт не работает или работает неправильно, раскомментируйте и укажите основной домен в свойстве domain */
25	/* If the script does not work or does not work correctly, uncomment and specify the main domain in the domain property */
26	// domain: "Get-Web.Site"
27
28};
29
30$(function () {
31	/* Подключаем виджет google translate */
32	/* Connecting the google translate widget */
33	let script = document.createElement("script");
34	script.src = `//translate.google.com/translate_a/element.js?cb=TranslateWidgetIsLoaded`;
35	document.getElementsByTagName("head")[0].appendChild(script);
36});
37
38function TranslateWidgetIsLoaded() {
39	TranslateInit(googleTranslateConfig);
40}
41
42function TranslateInit(config) {
43	if (config.langFirstVisit && !$.cookie("googtrans")) {
44		/* Если установлен язык перевода для первого посещения и куки не назначены */
45		/* If the translation language is installed for the first visit and cookies are not assigned */
46		TranslateCookieHandler("/auto/" + config.langFirstVisit);
47	}
48
49	let code = TranslateGetCode(config);
50
51	TranslateHtmlHandler(code);
52
53	if (code == config.lang) {
54		/* Если язык по умолчанию, совпадает с языком на который переводим, то очищаем куки */
55		/* If the default language is the same as the language we are translating into, then we clear the cookies */
56		TranslateCookieHandler(null, config.domain);
57	}
58
59	if (config.testWord) TranslateMutationObserver(config.testWord, code == config.lang);
60
61
62	/* Инициализируем виджет с языком по умолчанию */
63	/* Initialize the widget with the default language */
64	new google.translate.TranslateElement({
65		pageLanguage: config.lang,
66		multilanguagePage: true, // Your page contains content in more than one languages
67	});
68
69	/* Вешаем событие  клик на флаги */
70	/* Assigning a handler to the flags */
71	$("[data-google-lang]").click(function () {
72		TranslateCookieHandler(
73			"/auto/" + $(this).attr("data-google-lang"),
74			config.domain
75		);
76		/* Перезагружаем страницу */
77		/* Reloading the page */
78		window.location.reload();
79	});
80}
81
82function TranslateGetCode(config) {
83	/* Если куки нет, то передаем дефолтный язык */
84	/* If there are no cookies, then we pass the default language */
85	let lang =
86		$.cookie("googtrans") != undefined && $.cookie("googtrans") != "null"
87			? $.cookie("googtrans")
88			: config.lang;
89	return lang.match(/(?!^\/)[^\/]*$/gm)[0];
90}
91
92function TranslateCookieHandler(val, domain) {
93	/* Записываем куки /язык_который_переводим/язык_на_который_переводим */
94	/* Writing down cookies /language_for_translation/the_language_we_are_translating_into */
95	$.cookie("googtrans", val, {
96		domain: document.domain,
97		path: '/'
98	});
99	$.cookie("googtrans", val, {
100		domain: "." + document.domain,
101		path: '/'
102	});
103
104	if (domain == "undefined") return;
105	/* записываем куки для домена, если он назначен в конфиге */
106	/* Writing down cookies for the domain, if it is assigned in the config */
107	$.cookie("googtrans", val, {
108		domain: domain,
109		path: '/'
110	});
111
112	$.cookie("googtrans", val, {
113		domain: "." + domain,
114		path: '/'
115	});
116}
117
118function TranslateHtmlHandler(code) {
119	/* Получаем язык на который переводим и производим необходимые манипуляции с DOM */
120	/* We get the language to which we translate and produce the necessary manipulations with DOM */
121	$('[data-google-lang="' + code + '"]').addClass("language__img_active");
122}
123
124
125function TranslateMutationObserver(word, isOrigin) {
126
127	if (isOrigin) {
128		document.dispatchEvent(new CustomEvent("FinishTranslate"));
129	} else {
130
131		/* Создаем скрытый блок в который добавляем тестовое слово на оригинальном языке. Это позволит нам отследить момент когда сайт будет переведен и вызвать событие "FinishTranslate"  */
132		/* Creating a hidden block in which we add a test word in the original language. This will allow us to track the moment when the site is translated and trigger the "FinishTranslate" event  */
133
134		let div = document.createElement('div');
135		div.id = 'googleTranslateTestWord';
136		div.innerHTML = word;
137		div.style.display = 'none';
138		document.body.prepend(div);
139
140		let observer = new MutationObserver(() => {
141			document.dispatchEvent(new CustomEvent("FinishTranslate"));
142			observer.disconnect();
143		});
144
145		observer.observe(div, {
146			childList: false,
147			subtree: true,
148			characterDataOldValue: true
149		});
150	}
151}

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.