@zachhandley/ez-i18n 0.3.15 → 0.3.16
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.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/middleware.js +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +2 -2
- package/dist/{types-Cg77gLzO.d.ts → types-CE7B9s_c.d.ts} +8 -0
- package/dist/utils/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/EzI18nHead.astro +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AstroIntegration } from 'astro';
|
|
2
|
-
import { E as EzI18nConfig } from './types-
|
|
3
|
-
export { T as TranslateFunction } from './types-
|
|
2
|
+
import { E as EzI18nConfig } from './types-CE7B9s_c.js';
|
|
3
|
+
export { T as TranslateFunction } from './types-CE7B9s_c.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Comprehensive locale database for ez-i18n
|
package/dist/index.js
CHANGED
|
@@ -966,7 +966,7 @@ function ezI18n(config) {
|
|
|
966
966
|
import { initLocale, setTranslations } from '@zachhandley/ez-i18n/runtime';
|
|
967
967
|
|
|
968
968
|
document.addEventListener('astro:after-swap', () => {
|
|
969
|
-
const initData = globalThis.
|
|
969
|
+
const initData = globalThis.__EZ_I18N__;
|
|
970
970
|
if (initData) {
|
|
971
971
|
initLocale(initData.locale, initData.translations);
|
|
972
972
|
setTranslations(initData.translations);
|
package/dist/middleware.js
CHANGED
|
@@ -46,7 +46,7 @@ var onRequest = defineMiddleware(async ({ cookies, request, locals, redirect },
|
|
|
46
46
|
try {
|
|
47
47
|
const { loadTranslations } = await import("ez-i18n:translations");
|
|
48
48
|
locals.translations = await loadTranslations(locale);
|
|
49
|
-
globalThis.
|
|
49
|
+
globalThis.__EZ_I18N__ = {
|
|
50
50
|
locale,
|
|
51
51
|
translations: locals.translations
|
|
52
52
|
};
|
package/dist/runtime/index.d.ts
CHANGED
package/dist/runtime/index.js
CHANGED
|
@@ -81,7 +81,7 @@ function getTranslations() {
|
|
|
81
81
|
function getTranslationsWithSSRFallback() {
|
|
82
82
|
const trans = translations.get();
|
|
83
83
|
if (Object.keys(trans).length === 0) {
|
|
84
|
-
const ssrTrans = globalThis.
|
|
84
|
+
const ssrTrans = globalThis.__EZ_I18N__?.translations;
|
|
85
85
|
if (ssrTrans) {
|
|
86
86
|
return ssrTrans;
|
|
87
87
|
}
|
|
@@ -101,7 +101,7 @@ function t(key, params) {
|
|
|
101
101
|
}
|
|
102
102
|
function tc(key, params) {
|
|
103
103
|
return computed(translations, (trans) => {
|
|
104
|
-
const effectiveTrans = Object.keys(trans).length === 0 ? globalThis.
|
|
104
|
+
const effectiveTrans = Object.keys(trans).length === 0 ? globalThis.__EZ_I18N__?.translations ?? trans : trans;
|
|
105
105
|
const value = getNestedValue(effectiveTrans, key);
|
|
106
106
|
if (typeof value !== "string") {
|
|
107
107
|
if (typeof import.meta !== "undefined" && import.meta.env?.DEV) {
|
|
@@ -84,6 +84,10 @@ type TranslateFunction = (key: string, params?: Record<string, string | number>)
|
|
|
84
84
|
/**
|
|
85
85
|
* Augment Astro's locals type
|
|
86
86
|
*/
|
|
87
|
+
interface EzI18nContext {
|
|
88
|
+
locale: string;
|
|
89
|
+
translations: Record<string, unknown>;
|
|
90
|
+
}
|
|
87
91
|
declare global {
|
|
88
92
|
namespace App {
|
|
89
93
|
interface Locals {
|
|
@@ -95,6 +99,10 @@ declare global {
|
|
|
95
99
|
t: TranslateFunction;
|
|
96
100
|
}
|
|
97
101
|
}
|
|
102
|
+
var __EZ_I18N__: EzI18nContext | undefined;
|
|
103
|
+
var __EZ_I18N_ASSETS__: {
|
|
104
|
+
fetch: (req: Request | URL | string) => Promise<Response>;
|
|
105
|
+
} | undefined;
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
export type { EzI18nConfig as E, LocaleTranslationPath as L, TranslateFunction as T, TranslationsConfig as a, TranslationCache as b };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LocaleTranslationPath, a as TranslationsConfig, b as TranslationCache } from '../types-
|
|
1
|
+
import { L as LocaleTranslationPath, a as TranslationsConfig, b as TranslationCache } from '../types-CE7B9s_c.js';
|
|
2
2
|
|
|
3
3
|
type PathType = 'file' | 'folder' | 'glob' | 'array';
|
|
4
4
|
/**
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ const serializedTranslations = JSON.stringify(translations);
|
|
|
44
44
|
const translations = JSON.parse(script.dataset.ezI18nTranslations || '{}');
|
|
45
45
|
|
|
46
46
|
// Store for runtime initialization (globalThis is SSR-safe and equals window in browsers)
|
|
47
|
-
globalThis.
|
|
47
|
+
globalThis.__EZ_I18N__ = { locale, translations };
|
|
48
48
|
})();
|
|
49
49
|
</script>
|
|
50
50
|
|
|
@@ -53,9 +53,9 @@ const serializedTranslations = JSON.stringify(translations);
|
|
|
53
53
|
import { initLocale, setTranslations } from '@zachhandley/ez-i18n/runtime';
|
|
54
54
|
|
|
55
55
|
// Get initialization data from inline script
|
|
56
|
-
// Note: Don't delete
|
|
56
|
+
// Note: Don't delete __EZ_I18N__ here - other bundles (Vue, React)
|
|
57
57
|
// may need to read it to initialize their own store instances
|
|
58
|
-
const initData =
|
|
58
|
+
const initData = globalThis.__EZ_I18N__;
|
|
59
59
|
if (initData) {
|
|
60
60
|
initLocale(initData.locale, initData.translations);
|
|
61
61
|
setTranslations(initData.translations);
|