@lark-apaas/client-toolkit-lite 1.1.4 → 1.1.5
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.
- package/dist/index.cjs +45 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -571,9 +571,52 @@ var messages = {
|
|
|
571
571
|
var messages_default = messages;
|
|
572
572
|
|
|
573
573
|
// src/utils/locale.ts
|
|
574
|
+
var STORAGE_KEY = "miaoda:preview-locale";
|
|
575
|
+
function toLocale(value) {
|
|
576
|
+
const lang = value ?? "zh";
|
|
577
|
+
return lang.toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
578
|
+
}
|
|
579
|
+
__name(toLocale, "toLocale");
|
|
580
|
+
function readLocaleFromQuery() {
|
|
581
|
+
if (typeof window === "undefined") return null;
|
|
582
|
+
try {
|
|
583
|
+
const value = new URLSearchParams(window.location.search).get("locale");
|
|
584
|
+
return value && value.length > 0 ? value : null;
|
|
585
|
+
} catch {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
__name(readLocaleFromQuery, "readLocaleFromQuery");
|
|
590
|
+
function readLocaleFromStorage() {
|
|
591
|
+
if (typeof window === "undefined") return null;
|
|
592
|
+
try {
|
|
593
|
+
const value = window.localStorage?.getItem(STORAGE_KEY);
|
|
594
|
+
return value && value.length > 0 ? value : null;
|
|
595
|
+
} catch {
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
__name(readLocaleFromStorage, "readLocaleFromStorage");
|
|
600
|
+
function writeLocaleToStorage(value) {
|
|
601
|
+
if (typeof window === "undefined") return;
|
|
602
|
+
try {
|
|
603
|
+
window.localStorage?.setItem(STORAGE_KEY, value);
|
|
604
|
+
} catch {
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
__name(writeLocaleToStorage, "writeLocaleToStorage");
|
|
574
608
|
function getLocale() {
|
|
575
|
-
|
|
576
|
-
|
|
609
|
+
if (process.env.NODE_ENV === "production") {
|
|
610
|
+
return toLocale(navigator.language);
|
|
611
|
+
}
|
|
612
|
+
const fromQuery = readLocaleFromQuery();
|
|
613
|
+
if (fromQuery) {
|
|
614
|
+
writeLocaleToStorage(fromQuery);
|
|
615
|
+
return toLocale(fromQuery);
|
|
616
|
+
}
|
|
617
|
+
const fromStorage = readLocaleFromStorage();
|
|
618
|
+
if (fromStorage) return toLocale(fromStorage);
|
|
619
|
+
return toLocale(navigator.language);
|
|
577
620
|
}
|
|
578
621
|
__name(getLocale, "getLocale");
|
|
579
622
|
|