@zachhandley/ez-i18n 0.3.7 → 0.3.9

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.
@@ -42,6 +42,10 @@ var onRequest = defineMiddleware(async ({ cookies, request, locals, redirect },
42
42
  try {
43
43
  const { loadTranslations } = await import("ez-i18n:translations");
44
44
  locals.translations = await loadTranslations(locale);
45
+ globalThis.__EZ_I18N_SSR__ = {
46
+ locale,
47
+ translations: locals.translations
48
+ };
45
49
  } catch {
46
50
  locals.translations = {};
47
51
  }
@@ -78,8 +78,18 @@ function getLocale() {
78
78
  function getTranslations() {
79
79
  return translations.get();
80
80
  }
81
- function t(key, params) {
81
+ function getTranslationsWithSSRFallback() {
82
82
  const trans = translations.get();
83
+ if (Object.keys(trans).length === 0) {
84
+ const ssrTrans = globalThis.__EZ_I18N_SSR__?.translations;
85
+ if (ssrTrans) {
86
+ return ssrTrans;
87
+ }
88
+ }
89
+ return trans;
90
+ }
91
+ function t(key, params) {
92
+ const trans = getTranslationsWithSSRFallback();
83
93
  const value = getNestedValue(trans, key);
84
94
  if (typeof value !== "string") {
85
95
  if (typeof import.meta !== "undefined" && import.meta.env?.DEV) {
@@ -91,7 +101,8 @@ function t(key, params) {
91
101
  }
92
102
  function tc(key, params) {
93
103
  return computed(translations, (trans) => {
94
- const value = getNestedValue(trans, key);
104
+ const effectiveTrans = Object.keys(trans).length === 0 ? globalThis.__EZ_I18N_SSR__?.translations ?? trans : trans;
105
+ const value = getNestedValue(effectiveTrans, key);
95
106
  if (typeof value !== "string") {
96
107
  if (typeof import.meta !== "undefined" && import.meta.env?.DEV) {
97
108
  console.warn("[ez-i18n] Missing translation:", key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },