PageSourceSearch

https://newsgomel.by/bitrix/templates/gv/js/google-translate.js

js newsgomel.by collected 2026-10-02 03:08:00 UTC 3,102 bytes, 92 lines download raw bytes

1const googleTranslateConfig = {
2    lang: "ru",
3};
4
5function TranslateInit() {
6
7    let code = TranslateGetCode();
8
9
10    if (code == googleTranslateConfig.lang) {
11        // Если язык по умолчанию, совпадает с языком на который переводим
12        // То очищаем куки
13        TranslateClearCookie();
14    }
15
16    // Инициализируем виджет с языком по умолчанию
17     //new google.translate.TranslateElement({pageLanguage: 'ru', includedLanguages: 'en,ru,be', layout: google.translate.TranslateElement.InlineLayout.SIMPLE, autoDisplay: false}, 'google_translate_element');
18
19    if(getCookie('glang') == 'be'){
20        $('[data-google-lang="be"]').addClass('_active');
21        new google.translate.TranslateElement({
22            pageLanguage: googleTranslateConfig.lang,
23        });
24    }else{
25        $('[data-google-lang="ru"]').addClass('_active');
26    }
27
28    // Вешаем событие  клик на флаги
29    $('[data-google-lang]').click(function () {
30        TranslateSetCookie($(this).attr("data-google-lang"))
31
32        //console.log($(this).attr("data-google-lang"));
33        // Перезагружаем страницу
34        window.location.reload();
35    });
36}
37
38function TranslateGetCode() {
39    // Если куки нет, то передаем дефолтный язык
40    let lang = (getCookie('googtrans') != undefined && getCookie('googtrans') != "null") ? getCookie('googtrans') : googleTranslateConfig.lang;
41    return lang.substr(-2);
42}
43
44function TranslateClearCookie() {
45    setCookie('googtrans', null);
46    setCookie("googtrans", null, {
47        domain: "." + document.domain,
48    });
49}
50
51function TranslateSetCookie(code) {
52    //console.log(code);
53    // Записываем куки /язык_который_переводим/язык_на_который_переводим
54    setCookie("glang", code);
55    setCookie('googtrans', "/auto/" + code);
56    setCookie("googtrans", "/auto/" + code, {
57        domain: "." + document.domain,
58    });
59
60}
61
62function getCookie(name) {
63    let matches = document.cookie.match(new RegExp(
64        "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
65    ));
66    return matches ? decodeURIComponent(matches[1]) : undefined;
67}
68
69function setCookie(name, value, options = {}) {
70
71    options = {
72        path: '/',
73        // при необходимости добавьте другие значения по умолчанию
74        ...options
75    };
76
77    if (options.expires instanceof Date) {
78        options.expires = options.expires.toUTCString();
79    }
80
81    let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
82
83    for (let optionKey in options) {
84        updatedCookie += "; " + optionKey;
85        let optionValue = options[optionKey];
86        if (optionValue !== true) {
87            updatedCookie += "=" + optionValue;
88        }
89    }
90
91    document.cookie = updatedCookie;
92}

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.