@tolgee/core 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -130,40 +130,37 @@
130
130
  }
131
131
  Object.defineProperty(Properties.prototype, "currentLanguage", {
132
132
  get: function () {
133
- var result;
134
- if (this.config.forceLanguage) {
133
+ var _a;
134
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.forceLanguage) {
135
135
  return this.config.forceLanguage;
136
136
  }
137
- if (typeof localStorage !== 'undefined') {
138
- var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY);
137
+ if (this._currentLanguage) {
138
+ return this._currentLanguage;
139
+ }
140
+ if (this.config.enableLanguageStore) {
141
+ var storedLanguage = this.getStoredLanguage();
139
142
  if (storedLanguage) {
140
- result = storedLanguage;
141
- }
142
- if (this.config.availableLanguages) {
143
- var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(result) > -1;
144
- if (!isSavedLanguageAvailable) {
145
- result = undefined;
146
- }
143
+ return storedLanguage;
147
144
  }
148
145
  }
149
- else {
150
- result = this._currentLanguage;
151
- }
152
- if (!result) {
153
- result = this.getLanguageByNavigator();
154
- this.currentLanguage = result;
146
+ if (this.config.enableLanguageDetection) {
147
+ var detectedLanguage = this.getLanguageByNavigator();
148
+ if (detectedLanguage) {
149
+ return detectedLanguage;
150
+ }
155
151
  }
156
- return result;
152
+ return this.config.defaultLanguage;
157
153
  },
158
154
  set: function (language) {
155
+ var _a;
159
156
  if (!language) {
160
157
  throw new Error("Setting invalid language value ".concat(language));
161
158
  }
162
- if (typeof localStorage === 'undefined') {
163
- this._currentLanguage = language;
164
- return;
159
+ this._currentLanguage = language;
160
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableLanguageStore) &&
161
+ typeof localStorage !== 'undefined') {
162
+ localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language);
165
163
  }
166
- localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language);
167
164
  },
168
165
  enumerable: false,
169
166
  configurable: true
@@ -178,6 +175,18 @@
178
175
  enumerable: false,
179
176
  configurable: true
180
177
  });
178
+ Properties.prototype.getStoredLanguage = function () {
179
+ if (typeof localStorage !== 'undefined') {
180
+ var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY);
181
+ if (!this.config.availableLanguages) {
182
+ return storedLanguage;
183
+ }
184
+ var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(storedLanguage) > -1;
185
+ if (isSavedLanguageAvailable) {
186
+ return storedLanguage;
187
+ }
188
+ }
189
+ };
181
190
  Properties.prototype.getLanguageByNavigator = function () {
182
191
  if (typeof window !== 'undefined' && this.config.availableLanguages) {
183
192
  var preferred_1 = window.navigator.language;
@@ -192,7 +201,6 @@
192
201
  return twoLetterMatch;
193
202
  }
194
203
  }
195
- return this.config.defaultLanguage;
196
204
  };
197
205
  return Properties;
198
206
  }());
@@ -1636,7 +1644,18 @@
1636
1644
  function TolgeeConfig(config) {
1637
1645
  this.inputPrefix = '%-%tolgee:';
1638
1646
  this.inputSuffix = '%-%';
1647
+ /**
1648
+ * Used when auto detection is not available or is turned off
1649
+ */
1639
1650
  this.defaultLanguage = 'en';
1651
+ /**
1652
+ * Store user language in localStorage (default: true)
1653
+ */
1654
+ this.enableLanguageStore = true;
1655
+ /**
1656
+ * Use auto language detection by browser locale (default: true)
1657
+ */
1658
+ this.enableLanguageDetection = true;
1640
1659
  this.filesUrlPrefix = 'i18n/';
1641
1660
  this.tagAttributes = {
1642
1661
  textarea: ['placeholder'],
@@ -1749,7 +1768,7 @@
1749
1768
  this.handshake = function () {
1750
1769
  var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
1751
1770
  //remove properties, which cannot be sent by window.postMessage
1752
- staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.0.0" });
1771
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.2.0" });
1753
1772
  var timer = null;
1754
1773
  var ping = function () {
1755
1774
  _this.messages.send('TOLGEE_READY', sharedConfiguration);