typed-locales 1.0.48 → 1.0.49

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.
@@ -8,6 +8,6 @@ interface TranslationState {
8
8
  setLocale: (locale: Locales) => Promise<void>;
9
9
  t: TranslateFunctionType;
10
10
  }
11
- export declare const initZustand: (allTranslations: Record<Locales, TranslationLoader | TranslationType>, extraFormatters: ExtraFormatters) => import("zustand").UseBoundStore<import("zustand").StoreApi<TranslationState>>;
11
+ export declare const initZustand: (allTranslations: Record<Locales, TranslationLoader | TranslationType>, extraFormatters: ExtraFormatters, defaultLocale?: Locales) => import("zustand").UseBoundStore<import("zustand").StoreApi<TranslationState>>;
12
12
  export {};
13
13
  //# sourceMappingURL=zustand.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zustand.d.ts","sourceRoot":"","sources":["../../src/adapters/zustand.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,eAAe,EAEpB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,MAAM,aAAa,CAAC;AAErB,KAAK,iBAAiB,GAAG,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC,CAAC;AAErE,UAAU,gBAAgB;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,EAAE,qBAAqB,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,GACvB,iBAAiB,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,CAAC,EACrE,iBAAiB,eAAe,kFAmChC,CAAC"}
1
+ {"version":3,"file":"zustand.d.ts","sourceRoot":"","sources":["../../src/adapters/zustand.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,eAAe,EAEpB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,MAAM,aAAa,CAAC;AAErB,KAAK,iBAAiB,GAAG,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC,CAAC;AAErE,UAAU,gBAAgB;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,EAAE,qBAAqB,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,GACvB,iBAAiB,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,CAAC,EACrE,iBAAiB,eAAe,EAChC,gBAAgB,OAAO,kFA8CvB,CAAC"}
@@ -1,10 +1,13 @@
1
1
  import { create } from 'zustand';
2
2
  import { getTranslate, } from '../index.js';
3
- export const initZustand = (allTranslations, extraFormatters) => {
3
+ export const initZustand = (allTranslations, extraFormatters, defaultLocale) => {
4
4
  const identityTranslate = ((key) => key);
5
+ if (defaultLocale && typeof allTranslations[defaultLocale] !== 'object') {
6
+ throw new Error('Default locale in all translations object cant be a promise');
7
+ }
5
8
  return create((set, get) => ({
6
9
  isLoading: false,
7
- locale: undefined,
10
+ locale: defaultLocale,
8
11
  setLocale: async (targetLocale) => {
9
12
  if (get().locale === targetLocale)
10
13
  return;
@@ -28,6 +31,8 @@ export const initZustand = (allTranslations, extraFormatters) => {
28
31
  set({ isLoading: false });
29
32
  }
30
33
  },
31
- t: identityTranslate,
34
+ t: defaultLocale
35
+ ? getTranslate(allTranslations[defaultLocale], defaultLocale, extraFormatters)
36
+ : identityTranslate,
32
37
  }));
33
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-locales",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "Type safe utilities for translating strings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",