@tolgee/core 4.0.0 → 4.1.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.
@@ -128,40 +128,36 @@ var Properties = /** @class */ (function () {
128
128
  }
129
129
  Object.defineProperty(Properties.prototype, "currentLanguage", {
130
130
  get: function () {
131
- var result;
132
- if (this.config.forceLanguage) {
131
+ var _a;
132
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.forceLanguage) {
133
133
  return this.config.forceLanguage;
134
134
  }
135
- if (typeof localStorage !== 'undefined') {
136
- var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY);
135
+ if (this._currentLanguage) {
136
+ return this._currentLanguage;
137
+ }
138
+ if (this.config.languageStore) {
139
+ var storedLanguage = this.getStoredLanguage();
137
140
  if (storedLanguage) {
138
- result = storedLanguage;
139
- }
140
- if (this.config.availableLanguages) {
141
- var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(result) > -1;
142
- if (!isSavedLanguageAvailable) {
143
- result = undefined;
144
- }
141
+ return storedLanguage;
145
142
  }
146
143
  }
147
- else {
148
- result = this._currentLanguage;
149
- }
150
- if (!result) {
151
- result = this.getLanguageByNavigator();
152
- this.currentLanguage = result;
144
+ if (this.config.languageDetect) {
145
+ var detectedLanguage = this.getLanguageByNavigator();
146
+ if (detectedLanguage) {
147
+ return detectedLanguage;
148
+ }
153
149
  }
154
- return result;
150
+ return this.config.defaultLanguage;
155
151
  },
156
152
  set: function (language) {
153
+ var _a;
157
154
  if (!language) {
158
155
  throw new Error("Setting invalid language value ".concat(language));
159
156
  }
160
- if (typeof localStorage === 'undefined') {
161
- this._currentLanguage = language;
162
- return;
157
+ this._currentLanguage = language;
158
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.languageStore) && typeof localStorage !== 'undefined') {
159
+ localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language);
163
160
  }
164
- localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language);
165
161
  },
166
162
  enumerable: false,
167
163
  configurable: true
@@ -176,6 +172,18 @@ var Properties = /** @class */ (function () {
176
172
  enumerable: false,
177
173
  configurable: true
178
174
  });
175
+ Properties.prototype.getStoredLanguage = function () {
176
+ if (typeof localStorage !== 'undefined') {
177
+ var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY);
178
+ if (!this.config.availableLanguages) {
179
+ return storedLanguage;
180
+ }
181
+ var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(storedLanguage) > -1;
182
+ if (isSavedLanguageAvailable) {
183
+ return storedLanguage;
184
+ }
185
+ }
186
+ };
179
187
  Properties.prototype.getLanguageByNavigator = function () {
180
188
  if (typeof window !== 'undefined' && this.config.availableLanguages) {
181
189
  var preferred_1 = window.navigator.language;
@@ -190,7 +198,6 @@ var Properties = /** @class */ (function () {
190
198
  return twoLetterMatch;
191
199
  }
192
200
  }
193
- return this.config.defaultLanguage;
194
201
  };
195
202
  return Properties;
196
203
  }());
@@ -1634,7 +1641,18 @@ var TolgeeConfig = /** @class */ (function () {
1634
1641
  function TolgeeConfig(config) {
1635
1642
  this.inputPrefix = '%-%tolgee:';
1636
1643
  this.inputSuffix = '%-%';
1644
+ /**
1645
+ * Used when auto detection is not available or is turned off
1646
+ */
1637
1647
  this.defaultLanguage = 'en';
1648
+ /**
1649
+ * Store user language in localStorage (default: true)
1650
+ */
1651
+ this.languageStore = true;
1652
+ /**
1653
+ * Use auto language detection by browser locale (default: true)
1654
+ */
1655
+ this.languageDetect = true;
1638
1656
  this.filesUrlPrefix = 'i18n/';
1639
1657
  this.tagAttributes = {
1640
1658
  textarea: ['placeholder'],
@@ -1747,7 +1765,7 @@ var PluginManager = /** @class */ (function () {
1747
1765
  this.handshake = function () {
1748
1766
  var sharedConfiguration = __assign(__assign({}, _this.properties), { config: __assign(__assign({}, _this.properties.config), {
1749
1767
  //remove properties, which cannot be sent by window.postMessage
1750
- staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.0.0" });
1768
+ staticData: undefined, targetElement: undefined, _targetElement: undefined, ui: undefined }), uiPresent: Boolean(_this.properties.config.ui), uiVersion: "4.1.0" });
1751
1769
  var timer = null;
1752
1770
  var ping = function () {
1753
1771
  _this.messages.send('TOLGEE_READY', sharedConfiguration);