PageSourceSearch

https://www.dealstravels.com/lang.js

js dealstravels.com collected 2026-10-02 01:27:00 UTC 3,898 bytes, 121 lines download raw bytes

1(function () {
2  var LANGS = window.SITE_LANGS || ["es", "en"];
3  var I18N = window.SITE_I18N || {};
4  var DEFAULT = "es";
5
6  function detectLang() {
7    var path = location.pathname.replace(/\/+$/, "") || "/";
8    var parts = path.split("/").filter(Boolean);
9    if (parts.length && LANGS.indexOf(parts[0]) !== -1) return parts[0];
10    var q = new URLSearchParams(location.search).get("lang");
11    if (q && LANGS.indexOf(q) !== -1) return q;
12    return DEFAULT;
13  }
14
15  function pageKey() {
16    var path = location.pathname.replace(/\/+$/, "") || "/";
17    var parts = path.split("/").filter(Boolean);
18    if (parts.length && LANGS.indexOf(parts[0]) !== -1) parts.shift();
19    var leaf = parts[0] || "";
20    if (!leaf || leaf === "index.html") return "index";
21    if (leaf.indexOf("privacidad") === 0) return "privacidad";
22    if (leaf.indexOf("terminos") === 0) return "terminos";
23    if (leaf.indexOf("reembolso") === 0 || leaf === "refund") return "reembolso";
24    if (leaf.indexOf("comprar") === 0) return "comprar";
25    return "index";
26  }
27
28  function localizedPath(lang, page) {
29    var base =
30      page === "index"
31        ? "/"
32        : "/" +
33          ({
34            privacidad: "privacidad",
35            terminos: "terminos",
36            reembolso: "reembolso",
37            comprar: "comprar",
38          }[page] || page);
39    if (lang === DEFAULT) return base === "/" ? "/" : base;
40    return "/" + lang + (base === "/" ? "/" : base);
41  }
42
43  function t(key, vars) {
44    var lang = window.SITE_LANG || DEFAULT;
45    var dict = I18N[lang] || I18N[DEFAULT] || {};
46    var text = dict[key] || (I18N[DEFAULT] && I18N[DEFAULT][key]) || key;
47    if (vars) {
48      Object.keys(vars).forEach(function (k) {
49        text = text.replace(new RegExp("\\{" + k + "\\}", "g"), vars[k]);
50      });
51    }
52    return text;
53  }
54
55  function apply() {
56    var lang = detectLang();
57    window.SITE_LANG = lang;
58    var dict = I18N[lang] || I18N[DEFAULT];
59    document.documentElement.lang = lang === "zh" ? "zh-CN" : lang;
60    document.documentElement.dir = (dict && dict.dir) || "ltr";
61
62    document.querySelectorAll("[data-i18n]").forEach(function (el) {
63      var key = el.getAttribute("data-i18n");
64      var val = t(key);
65      if (val) el.textContent = val;
66    });
67
68    document.querySelectorAll("[data-i18n-html]").forEach(function (el) {
69      var key = el.getAttribute("data-i18n-html");
70      var val = t(key);
71      if (val) el.innerHTML = val;
72    });
73
74    var titleKey = document.body.getAttribute("data-title-key");
75    if (titleKey) document.title = t(titleKey);
76
77    var bar = document.getElementById("lang-bar");
78    if (bar) {
79      var page = pageKey();
80      var html =
81        '<label data-i18n="lang_label">' +
82        t("lang_label") +
83        ":</label> ";
84      LANGS.forEach(function (code) {
85        var label = (I18N[code] && I18N[code].label) || code;
86        var href = localizedPath(code, page);
87        var qs = location.search;
88        // preserve query except bare ?lang=
89        if (qs && qs.indexOf("user_email") !== -1) {
90          href += qs;
91        } else if (qs && qs.indexOf("ok=") !== -1) {
92          href += qs;
93        }
94        var cls = code === lang ? "active" : "";
95        html +=
96          '<a class="' +
97          cls +
98          '" href="' +
99          href +
100          '" hreflang="' +
101          code +
102          '">' +
103          label +
104          "</a> ";
105      });
106      bar.innerHTML = html;
107    }
108
109    window.dispatchEvent(new CustomEvent("site-i18n-ready", { detail: { lang: lang, t: t } }));
110  }
111
112  window.siteT = t;
113  window.siteLocalizedPath = localizedPath;
114  window.sitePageKey = pageKey;
115
116  if (document.readyState === "loading") {
117    document.addEventListener("DOMContentLoaded", apply);
118  } else {
119    apply();
120  }
121})();

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.