PageSourceSearch

https://gulnar.bel.tr/lib/i18next/jquery-i18next.js

js gulnar.bel.tr collected 2026-10-02 20:28:04 UTC 3,781 bytes, 127 lines download raw bytes

vendor: 3,781 bytes, lines 1-127
1(function (global, factory) {
2  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3  typeof define === 'function' && define.amd ? define(factory) :
4  (global.jqueryI18next = factory());
5}(this, (function () { 'use strict';
6
7var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
8
9var defaults = {
10  tName: 't',
11  i18nName: 'i18n',
12  handleName: 'localize',
13  selectorAttr: 'data-i18n',
14  targetAttr: 'i18n-target',
15  optionsAttr: 'i18n-options',
16  useOptionsAttr: false,
17  parseDefaultValueFromContent: true
18};
19
20function init(i18next, $) {
21  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
22
23
24  options = _extends({}, defaults, options);
25
26  function parse(ele, key, opts) {
27    if (key.length === 0) return;
28
29    var attr = 'text';
30
31    if (key.indexOf('[') === 0) {
32      var parts = key.split(']');
33      key = parts[1];
34      attr = parts[0].substr(1, parts[0].length - 1);
35    }
36
37    if (key.indexOf(';') === key.length - 1) {
38      key = key.substr(0, key.length - 2);
39    }
40
41    function extendDefault(o, val) {
42      if (!options.parseDefaultValueFromContent) return o;
43      return _extends({}, o, { defaultValue: val });
44    }
45
46    if (attr === 'html') {
47      ele.html(i18next.t(key, extendDefault(opts, ele.html())));
48    } else if (attr === 'text') {
49      ele.text(i18next.t(key, extendDefault(opts, ele.text())));
50    } else if (attr === 'prepend') {
51      ele.prepend(i18next.t(key, extendDefault(opts, ele.html())));
52    } else if (attr === 'append') {
53      ele.append(i18next.t(key, extendDefault(opts, ele.html())));
54    } else if (attr.indexOf('data-') === 0) {
55      var dataAttr = attr.substr('data-'.length);
56      var translated = i18next.t(key, extendDefault(opts, ele.data(dataAttr)));
57
58      // we change into the data cache
59      ele.data(dataAttr, translated);
60      // we change into the dom
61      ele.attr(attr, translated);
62    } else {
63      ele.attr(attr, i18next.t(key, extendDefault(opts, ele.attr(attr))));
64    }
65  }
66
67  function localize(ele, opts) {
68    var key = ele.attr(options.selectorAttr);
69    if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val();
70    if (!key) return;
71
72    var target = ele,
73        targetSelector = ele.data(options.targetAttr);
74
75    if (targetSelector) target = ele.find(targetSelector) || ele;
76
77    if (!opts && options.useOptionsAttr === true) opts = ele.data(options.optionsAttr);
78
79    opts = opts || {};
80
81    if (key.indexOf(';') >= 0) {
82      var keys = key.split(';');
83
84      $.each(keys, function (m, k) {
85        if (k !== '') parse(target, k, opts);
86      });
87    } else {
88      parse(target, key, opts);
89    }
90
91    if (options.useOptionsAttr === true) {
92      var clone = {};
93      clone = _extends({ clone: clone }, opts);
94
95      delete clone.lng;
96      ele.data(options.optionsAttr, clone);
97    }
98  }
99
100  function handle(opts) {
101    return this.each(function () {
102      // localize element itself
103      localize($(this), opts);
104
105      // localize children
106      var elements = $(this).find('[' + options.selectorAttr + ']');
107      elements.each(function () {
108        localize($(this), opts);
109      });
110    });
111  };
112
113  // $.t $.i18n shortcut
114  $[options.tName] = i18next.t.bind(i18next);
115  $[options.i18nName] = i18next;
116
117  // selector function $(mySelector).localize(opts);
118  $.fn[options.handleName] = handle;
119}
120
121var index = {
122  init: init
123};
124
125return index;
126
127})));

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.