typed-locales 1.0.62 → 1.0.64

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.
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/adapters/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAEhF,OAAO,EACN,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,OAAO,EAEZ,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAMD,KAAK,gBAAgB,GAAG;KACtB,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAC5B,GAAG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,KAAK,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AA0B5C,eAAO,MAAM,SAAS,GACrB,qBAAqB,MAAM,EAC3B,iBAAiB,MAAM,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EACpE,iBAAiB,eAAe,EAChC,eAAe,OAAO,EACtB,oBAAoB,iBAAiB,oBAEM;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,4CAgFxE,CAAC;AAEF,eAAO,MAAM,cAAc,8BAM1B,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/adapters/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,EACN,YAAY,EACZ,KAAK,eAAe,EACpB,KAAK,OAAO,EAEZ,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAMD,KAAK,gBAAgB,GAAG;KACtB,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM;CAC5B,GAAG;IACH,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,KAAK,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AA0B5C,eAAO,MAAM,SAAS,GACrB,qBAAqB,MAAM,EAC3B,iBAAiB,MAAM,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EACpE,iBAAiB,eAAe,EAChC,eAAe,OAAO,EACtB,oBAAoB,iBAAiB,oBAEM;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,4CAkFxE,CAAC;AAEF,eAAO,MAAM,cAAc,8BAM1B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useCallback, useContext, useState } from 'react';
2
+ import { createContext, useCallback, useContext, useMemo, useState, } from 'react';
3
3
  import { getTranslate, } from '../index.js';
4
4
  const TranslationContext = createContext(undefined);
5
5
  const addExtraTranslations = (translation, extraTranslations, locale) => {
@@ -23,7 +23,7 @@ const addExtraTranslations = (translation, extraTranslations, locale) => {
23
23
  // Initial translation always should be loaded
24
24
  export const initReact = (defaultTranslations, allTranslations, extraFormatters, defaultLocale, extraTranslations) => {
25
25
  const TranslationProvider = ({ children }) => {
26
- const defaultTranslate = getTranslate(addExtraTranslations(defaultTranslations, extraTranslations ?? [], defaultLocale), defaultLocale, extraFormatters);
26
+ const defaultTranslate = useMemo(() => getTranslate(addExtraTranslations(defaultTranslations, extraTranslations ?? [], defaultLocale), defaultLocale, extraFormatters), []);
27
27
  const [state, setState] = useState({
28
28
  isLoading: false,
29
29
  locale: defaultLocale,
@@ -36,7 +36,7 @@ export const initReact = (defaultTranslations, allTranslations, extraFormatters,
36
36
  try {
37
37
  const translationOrLoader = allTranslations[targetLocale];
38
38
  if (!translationOrLoader) {
39
- throw new Error(`Translation loader for locale ${targetLocale} not found`);
39
+ throw new Error(`Translation loader not found`);
40
40
  }
41
41
  const translationData = (await translationOrLoader().then(t => t.default));
42
42
  setState({
@@ -46,7 +46,7 @@ export const initReact = (defaultTranslations, allTranslations, extraFormatters,
46
46
  });
47
47
  }
48
48
  catch (error) {
49
- console.error(`Failed to load translations for locale ${String(targetLocale)}:`, error);
49
+ console.error(`Failed to load translations for locale ${String(targetLocale)}:`, error?.message ?? error);
50
50
  setState(previous => ({ ...previous, isLoading: false }));
51
51
  }
52
52
  return targetLocale;
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export const getTranslate = (translations, locale, extraFormatters, baseTranslat
11
11
  let isPlural = false;
12
12
  let lastPart = '';
13
13
  for (const part of parts) {
14
- if (current && current[part]) {
14
+ if (current && current[part] !== undefined) {
15
15
  if (typeof current[part] === 'string') {
16
16
  value = current[part];
17
17
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-locales",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "description": "Type safe utilities for translating strings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",