@tolgee/core
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -12,3 +12,4 @@ import { TolgeeConfig } from './TolgeeConfig'; | ||
set preferredLanguages(languages: Set<string>); | ||
private getStoredLanguage; | ||
private getLanguageByNavigator; | ||
} |
@@ -8,36 +8,32 @@ var PREFERRED_LANGUAGES_LOCAL_STORAGE_KEY = '__tolgee_preferredLanguages'; | ||
get: function () { | ||
var result; | ||
if (this.config.forceLanguage) { | ||
var _a; | ||
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.forceLanguage) { | ||
return this.config.forceLanguage; | ||
} | ||
if (typeof localStorage !== 'undefined') { | ||
var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY); | ||
if (this._currentLanguage) { | ||
return this._currentLanguage; | ||
} | ||
if (this.config.languageStore) { | ||
var storedLanguage = this.getStoredLanguage(); | ||
if (storedLanguage) { | ||
result = storedLanguage; | ||
return storedLanguage; | ||
} | ||
if (this.config.availableLanguages) { | ||
var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(result) > -1; | ||
if (!isSavedLanguageAvailable) { | ||
result = undefined; | ||
} | ||
} | ||
if (this.config.languageDetect) { | ||
var detectedLanguage = this.getLanguageByNavigator(); | ||
if (detectedLanguage) { | ||
return detectedLanguage; | ||
} | ||
} | ||
else { | ||
result = this._currentLanguage; | ||
} | ||
if (!result) { | ||
result = this.getLanguageByNavigator(); | ||
this.currentLanguage = result; | ||
} | ||
return result; | ||
return this.config.defaultLanguage; | ||
}, | ||
set: function (language) { | ||
var _a; | ||
if (!language) { | ||
throw new Error("Setting invalid language value ".concat(language)); | ||
} | ||
if (typeof localStorage === 'undefined') { | ||
this._currentLanguage = language; | ||
return; | ||
this._currentLanguage = language; | ||
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.languageStore) && typeof localStorage !== 'undefined') { | ||
localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language); | ||
} | ||
localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language); | ||
}, | ||
@@ -57,2 +53,14 @@ enumerable: false, | ||
}); | ||
Properties.prototype.getStoredLanguage = function () { | ||
if (typeof localStorage !== 'undefined') { | ||
var storedLanguage = localStorage.getItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY); | ||
if (!this.config.availableLanguages) { | ||
return storedLanguage; | ||
} | ||
var isSavedLanguageAvailable = this.config.availableLanguages.indexOf(storedLanguage) > -1; | ||
if (isSavedLanguageAvailable) { | ||
return storedLanguage; | ||
} | ||
} | ||
}; | ||
Properties.prototype.getLanguageByNavigator = function () { | ||
@@ -72,3 +80,2 @@ if (typeof window !== 'undefined' && this.config.availableLanguages) { | ||
} | ||
return this.config.defaultLanguage; | ||
}; | ||
@@ -75,0 +82,0 @@ return Properties; |
@@ -9,6 +9,27 @@ import { Mode, TreeTranslationsData } from './types'; | ||
inputSuffix?: string; | ||
/** | ||
* Overrides all language settings | ||
*/ | ||
forceLanguage?: string; | ||
/** | ||
* Used when auto detection is not available or is turned off | ||
*/ | ||
defaultLanguage?: string; | ||
/** | ||
* Languages which can be used for language detection | ||
* and also limits which values can be stored | ||
*/ | ||
availableLanguages?: string[]; | ||
/** | ||
* Language which is used when no translation is available for current one | ||
*/ | ||
fallbackLanguage?: string; | ||
/** | ||
* Store user language in localStorage (default: true) | ||
*/ | ||
languageStore?: boolean; | ||
/** | ||
* Use auto language detection by browser locale (default: true) | ||
*/ | ||
languageDetect?: boolean; | ||
filesUrlPrefix?: string; | ||
@@ -15,0 +36,0 @@ watch?: boolean; |
@@ -14,3 +14,14 @@ import { NodeHelper } from './helpers/NodeHelper'; | ||
this.inputSuffix = '%-%'; | ||
/** | ||
* Used when auto detection is not available or is turned off | ||
*/ | ||
this.defaultLanguage = 'en'; | ||
/** | ||
* Store user language in localStorage (default: true) | ||
*/ | ||
this.languageStore = true; | ||
/** | ||
* Use auto language detection by browser locale (default: true) | ||
*/ | ||
this.languageDetect = true; | ||
this.filesUrlPrefix = 'i18n/'; | ||
@@ -17,0 +28,0 @@ this.tagAttributes = { |
{ | ||
"name": "@tolgee/core", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Library providing ability to translate messages directly in context of developed application.", | ||
@@ -64,3 +64,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "3302234c530a50fd20a89ba62e84aa45b880a720", | ||
"gitHead": "a593f31d12feb5c162f6100b92d9ad9850cccfcf", | ||
"publishConfig": { | ||
@@ -67,0 +67,0 @@ "access": "public" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3282625
22250