@jswork/i18n-language-detect
Advanced tools
Comparing version 1.0.29 to 1.0.30
@@ -162,3 +162,3 @@ "use strict"; | ||
var lang = languageQueryFn ? languageQueryFn() : (0, import_i18n_helper.getLanguage)(routerType, lookupQuerystring); | ||
var resLang = lang || navigator.language || store.getItem(this.cacheKey); | ||
var resLang = lang || store.getItem(this.cacheKey) || navigator.language; | ||
return (0, import_i18n_helper.stdLanguage)(resLang, fallbackLng); | ||
@@ -165,0 +165,0 @@ } |
// src/index.ts | ||
function _class_call_check(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for(var i = 0; i < props.length; i++){ | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _create_class(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _define_property(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _object_spread(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === "function") { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function(key) { | ||
_define_property(target, key, source[key]); | ||
}); | ||
} | ||
return target; | ||
} | ||
import { stdLanguage, getLanguage } from "@jswork/i18n-helper"; | ||
var MSG = { | ||
store_not_available: "i18next-browser-languagedetector: Using memory store. Can't persist language." | ||
store_not_available: "i18next-browser-languagedetector: Using memory store. Can't persist language." | ||
}; | ||
var MemoryStore = { | ||
data: {}, | ||
setItem: function setItem(key, value) { | ||
console.warn(MSG.store_not_available); | ||
this.data[key] = value; | ||
}, | ||
getItem: function getItem(key) { | ||
console.warn(MSG.store_not_available); | ||
return this.data[key]; | ||
} | ||
data: {}, | ||
setItem(key, value) { | ||
console.warn(MSG.store_not_available); | ||
this.data[key] = value; | ||
}, | ||
getItem(key) { | ||
console.warn(MSG.store_not_available); | ||
return this.data[key]; | ||
} | ||
}; | ||
var defaults = { | ||
lookupQuerystring: [ | ||
"language", | ||
"lang" | ||
], | ||
store: typeof localStorage !== "undefined" ? localStorage : MemoryStore, | ||
cacheNs: "", | ||
cacheKey: "i18next.lang", | ||
routerType: "hash", | ||
supportedLngs: [ | ||
"zh-CN", | ||
"en-US", | ||
"ru-RU" | ||
], | ||
fallbackLng: "en-US" | ||
lookupQuerystring: ["language", "lang"], | ||
store: typeof localStorage !== "undefined" ? localStorage : MemoryStore, | ||
cacheNs: "", | ||
cacheKey: "i18next.lang", | ||
routerType: "hash", | ||
supportedLngs: ["zh-CN", "en-US", "ru-RU"], | ||
fallbackLng: "en-US" | ||
}; | ||
var I18nLanguageDetect = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function I18nLanguageDetect() { | ||
_class_call_check(this, I18nLanguageDetect); | ||
this.options = _object_spread({}, defaults); | ||
} | ||
_create_class(I18nLanguageDetect, [ | ||
{ | ||
key: "cacheKey", | ||
get: function get() { | ||
var _this_options = this.options, cacheNs = _this_options.cacheNs, cacheKey = _this_options.cacheKey; | ||
var host = window.location.host; | ||
var ns = cacheNs || host; | ||
return "".concat(ns, "@").concat(cacheKey); | ||
} | ||
}, | ||
{ | ||
key: "init", | ||
value: function init(services) { | ||
var opts = services.languageUtils.options; | ||
this.services = services; | ||
this.options = _object_spread({}, defaults, opts); | ||
} | ||
}, | ||
{ | ||
key: "detect", | ||
value: function detect() { | ||
var _this_options = this.options, lookupQuerystring = _this_options.lookupQuerystring, languageQueryFn = _this_options.languageQueryFn, store = _this_options.store, fallbackLng = _this_options.fallbackLng, routerType = _this_options.routerType; | ||
var lang = languageQueryFn ? languageQueryFn() : getLanguage(routerType, lookupQuerystring); | ||
var resLang = lang || navigator.language || store.getItem(this.cacheKey); | ||
return stdLanguage(resLang, fallbackLng); | ||
} | ||
}, | ||
{ | ||
key: "cacheUserLanguage", | ||
value: function cacheUserLanguage(lng) { | ||
var store = this.options.store; | ||
store.setItem(this.cacheKey, lng); | ||
} | ||
} | ||
]); | ||
return I18nLanguageDetect; | ||
}(); | ||
var I18nLanguageDetect = class { | ||
constructor() { | ||
this.options = { ...defaults }; | ||
} | ||
get cacheKey() { | ||
const { cacheNs, cacheKey } = this.options; | ||
const { host } = window.location; | ||
const ns = cacheNs || host; | ||
return `${ns}@${cacheKey}`; | ||
} | ||
init(services) { | ||
const opts = services.languageUtils.options; | ||
this.services = services; | ||
this.options = { ...defaults, ...opts }; | ||
} | ||
detect() { | ||
const { lookupQuerystring, languageQueryFn, store, fallbackLng, routerType } = this.options; | ||
const lang = languageQueryFn ? languageQueryFn() : getLanguage(routerType, lookupQuerystring); | ||
const resLang = lang || store.getItem(this.cacheKey) || navigator.language; | ||
return stdLanguage(resLang, fallbackLng); | ||
} | ||
cacheUserLanguage(lng) { | ||
const { store } = this.options; | ||
store.setItem(this.cacheKey, lng); | ||
} | ||
}; | ||
I18nLanguageDetect.type = "languageDetector"; | ||
var src_default = I18nLanguageDetect; | ||
export { src_default as default }; | ||
export { | ||
src_default as default | ||
}; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@jswork/i18n-language-detect", | ||
"version": "1.0.29", | ||
"version": "1.0.30", | ||
"description": "Language detect plugin.", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "76b4317c0e1369f38e9e8d8940c2461c2d1aeb0c" | ||
"gitHead": "9190fb7cddb7338fadaedf17d79927d696f13123" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
18620
253