@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.js CHANGED
@@ -506,9 +506,52 @@ var messages = {
506
506
  var messages_default = messages;
507
507
 
508
508
  // src/utils/locale.ts
509
+ var STORAGE_KEY = "miaoda:preview-locale";
510
+ function toLocale(value) {
511
+ const lang = value ?? "zh";
512
+ return lang.toLowerCase().startsWith("zh") ? "zh" : "en";
513
+ }
514
+ __name(toLocale, "toLocale");
515
+ function readLocaleFromQuery() {
516
+ if (typeof window === "undefined") return null;
517
+ try {
518
+ const value = new URLSearchParams(window.location.search).get("locale");
519
+ return value && value.length > 0 ? value : null;
520
+ } catch {
521
+ return null;
522
+ }
523
+ }
524
+ __name(readLocaleFromQuery, "readLocaleFromQuery");
525
+ function readLocaleFromStorage() {
526
+ if (typeof window === "undefined") return null;
527
+ try {
528
+ const value = window.localStorage?.getItem(STORAGE_KEY);
529
+ return value && value.length > 0 ? value : null;
530
+ } catch {
531
+ return null;
532
+ }
533
+ }
534
+ __name(readLocaleFromStorage, "readLocaleFromStorage");
535
+ function writeLocaleToStorage(value) {
536
+ if (typeof window === "undefined") return;
537
+ try {
538
+ window.localStorage?.setItem(STORAGE_KEY, value);
539
+ } catch {
540
+ }
541
+ }
542
+ __name(writeLocaleToStorage, "writeLocaleToStorage");
509
543
  function getLocale() {
510
- const lang = navigator.language || "zh";
511
- return lang.startsWith("zh") ? "zh" : "en";
544
+ if (process.env.NODE_ENV === "production") {
545
+ return toLocale(navigator.language);
546
+ }
547
+ const fromQuery = readLocaleFromQuery();
548
+ if (fromQuery) {
549
+ writeLocaleToStorage(fromQuery);
550
+ return toLocale(fromQuery);
551
+ }
552
+ const fromStorage = readLocaleFromStorage();
553
+ if (fromStorage) return toLocale(fromStorage);
554
+ return toLocale(navigator.language);
512
555
  }
513
556
  __name(getLocale, "getLocale");
514
557