@zachhandley/ez-i18n 0.2.1 → 0.2.2

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,6 +1,5 @@
1
- import { setLocale } from './index.js';
1
+ import { setLocale } from '@zachhandley/ez-i18n/runtime';
2
2
  import { T as TranslateFunction } from '../types-Cd9e7Lkc.js';
3
- import 'nanostores';
4
3
 
5
4
  /**
6
5
  * React hook for i18n
@@ -1,49 +1,6 @@
1
1
  // src/runtime/react-plugin.ts
2
2
  import { useStore } from "@nanostores/react";
3
-
4
- // src/runtime/store.ts
5
- import { atom, computed } from "nanostores";
6
- import { persistentAtom } from "@nanostores/persistent";
7
- var serverLocale = atom(null);
8
- var localePreference = persistentAtom("ez-locale", "en", {
9
- encode: (value) => value,
10
- decode: (value) => value
11
- });
12
- var effectiveLocale = computed(
13
- [serverLocale, localePreference],
14
- (server, client) => server ?? client
15
- );
16
- var translations = atom({});
17
- var localeLoading = atom(false);
18
- async function setLocale(locale, options = {}) {
19
- const opts = typeof options === "string" ? { cookieName: options } : options;
20
- const { cookieName = "ez-locale", loadTranslations } = opts;
21
- localeLoading.set(true);
22
- try {
23
- if (loadTranslations) {
24
- const mod = await loadTranslations();
25
- const trans = "default" in mod ? mod.default : mod;
26
- translations.set(trans);
27
- }
28
- localePreference.set(locale);
29
- serverLocale.set(locale);
30
- if (typeof document !== "undefined") {
31
- document.cookie = `${cookieName}=${locale}; path=/; max-age=31536000; samesite=lax`;
32
- }
33
- if (typeof document !== "undefined") {
34
- document.dispatchEvent(
35
- new CustomEvent("ez-i18n:locale-changed", {
36
- detail: { locale },
37
- bubbles: true
38
- })
39
- );
40
- }
41
- } finally {
42
- localeLoading.set(false);
43
- }
44
- }
45
-
46
- // src/runtime/react-plugin.ts
3
+ import { effectiveLocale, translations, setLocale } from "@zachhandley/ez-i18n/runtime";
47
4
  function getNestedValue(obj, path) {
48
5
  const keys = path.split(".");
49
6
  let value = obj;
@@ -1,8 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { Plugin } from 'vue';
3
- import { setLocale } from './index.js';
3
+ import { setLocale } from '@zachhandley/ez-i18n/runtime';
4
4
  import { T as TranslateFunction } from '../types-Cd9e7Lkc.js';
5
- import 'nanostores';
6
5
 
7
6
  /**
8
7
  * Vue plugin that provides global $t(), $locale, and $setLocale
@@ -1,50 +1,7 @@
1
1
  // src/runtime/vue-plugin.ts
2
- import { computed as computed2 } from "vue";
2
+ import { computed } from "vue";
3
3
  import { useStore } from "@nanostores/vue";
4
-
5
- // src/runtime/store.ts
6
- import { atom, computed } from "nanostores";
7
- import { persistentAtom } from "@nanostores/persistent";
8
- var serverLocale = atom(null);
9
- var localePreference = persistentAtom("ez-locale", "en", {
10
- encode: (value) => value,
11
- decode: (value) => value
12
- });
13
- var effectiveLocale = computed(
14
- [serverLocale, localePreference],
15
- (server, client) => server ?? client
16
- );
17
- var translations = atom({});
18
- var localeLoading = atom(false);
19
- async function setLocale(locale, options = {}) {
20
- const opts = typeof options === "string" ? { cookieName: options } : options;
21
- const { cookieName = "ez-locale", loadTranslations } = opts;
22
- localeLoading.set(true);
23
- try {
24
- if (loadTranslations) {
25
- const mod = await loadTranslations();
26
- const trans = "default" in mod ? mod.default : mod;
27
- translations.set(trans);
28
- }
29
- localePreference.set(locale);
30
- serverLocale.set(locale);
31
- if (typeof document !== "undefined") {
32
- document.cookie = `${cookieName}=${locale}; path=/; max-age=31536000; samesite=lax`;
33
- }
34
- if (typeof document !== "undefined") {
35
- document.dispatchEvent(
36
- new CustomEvent("ez-i18n:locale-changed", {
37
- detail: { locale },
38
- bubbles: true
39
- })
40
- );
41
- }
42
- } finally {
43
- localeLoading.set(false);
44
- }
45
- }
46
-
47
- // src/runtime/vue-plugin.ts
4
+ import { effectiveLocale, translations, setLocale } from "@zachhandley/ez-i18n/runtime";
48
5
  function getNestedValue(obj, path) {
49
6
  const keys = path.split(".");
50
7
  let value = obj;
@@ -79,7 +36,7 @@ var ezI18nVue = {
79
36
  install(app) {
80
37
  const locale = useStore(effectiveLocale);
81
38
  const trans = useStore(translations);
82
- const transComputed = computed2(() => trans.value);
39
+ const transComputed = computed(() => trans.value);
83
40
  const t = createTranslateFunction(transComputed);
84
41
  app.config.globalProperties.$t = t;
85
42
  app.config.globalProperties.$locale = locale;
@@ -94,7 +51,7 @@ var ezI18nVue = {
94
51
  function useI18n() {
95
52
  const locale = useStore(effectiveLocale);
96
53
  const trans = useStore(translations);
97
- const transComputed = computed2(() => trans.value);
54
+ const transComputed = computed(() => trans.value);
98
55
  const t = createTranslateFunction(transComputed);
99
56
  return {
100
57
  t,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,5 +1,6 @@
1
1
  import { useStore } from '@nanostores/react';
2
- import { effectiveLocale, translations, setLocale } from './store';
2
+ // Import from package path (not relative) to ensure shared store instance
3
+ import { effectiveLocale, translations, setLocale } from '@zachhandley/ez-i18n/runtime';
3
4
  import type { TranslateFunction } from '../types';
4
5
 
5
6
  /**
@@ -1,7 +1,8 @@
1
1
  import type { App, Plugin, ComputedRef } from 'vue';
2
2
  import { computed } from 'vue';
3
3
  import { useStore } from '@nanostores/vue';
4
- import { effectiveLocale, translations, setLocale } from './store';
4
+ // Import from package path (not relative) to ensure shared store instance
5
+ import { effectiveLocale, translations, setLocale } from '@zachhandley/ez-i18n/runtime';
5
6
  import type { TranslateFunction } from '../types';
6
7
 
7
8
  /**