nuxt-i18n-micro 1.34.1 → 1.35.0
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/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/45243cb3-2689-40bc-a6bc-4f6112ff9879.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -0
- package/dist/runtime/components/i18n-switcher.vue +7 -2
- package/dist/runtime/composables/useLocaleHead.js +1 -1
- package/dist/runtime/translation-server-middleware.d.ts +2 -0
- package/dist/runtime/translation-server-middleware.js +26 -0
- package/package.json +2 -2
- package/dist/client/_nuxt/builds/meta/f4f9b29e-c87c-4731-99e1-f8100be361c1.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CBccCxXK.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.Bkv_zTjr.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DNen4El9.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1733169422939,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"45243cb3-2689-40bc-a6bc-4f6112ff9879",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CBccCxXK.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.Bkv_zTjr.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DNen4El9.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1733169422939,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"45243cb3-2689-40bc-a6bc-4f6112ff9879",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"45243cb3-2689-40bc-a6bc-4f6112ff9879","timestamp":1733169409982}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"45243cb3-2689-40bc-a6bc-4f6112ff9879","timestamp":1733169409982,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CBccCxXK.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.Bkv_zTjr.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DNen4El9.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/n4MbYZHF.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1733169422939,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"45243cb3-2689-40bc-a6bc-4f6112ff9879",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -453,6 +453,11 @@ const module = defineNuxtModule({
|
|
|
453
453
|
write: true,
|
|
454
454
|
getContents: () => `export const plural = ${options.plural.toString()};`
|
|
455
455
|
});
|
|
456
|
+
addTemplate({
|
|
457
|
+
filename: "i18n.config.mjs",
|
|
458
|
+
write: true,
|
|
459
|
+
getContents: () => `export const defaultLocale = "${options.defaultLocale}";`
|
|
460
|
+
});
|
|
456
461
|
const apiBaseUrl = (process.env.NUXT_I18N_APP_BASE_URL ?? options.apiBaseUrl ?? "_locales").replace(/^\/+|\/+$|\/{2,}/, "");
|
|
457
462
|
nuxt.options.runtimeConfig.public.i18nConfig = {
|
|
458
463
|
plural: void 0,
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
<NuxtLink
|
|
35
35
|
:class="`switcher-locale-${locale.code}`"
|
|
36
|
-
:to="
|
|
36
|
+
:to="switchLocaleRoute(locale.code)"
|
|
37
37
|
:style="[
|
|
38
38
|
linkStyle,
|
|
39
39
|
locale.code === currentLocale ? activeLinkStyle : {},
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
<script lang="ts" setup>
|
|
71
71
|
import { ref, computed } from 'vue'
|
|
72
72
|
import type { CSSProperties } from 'vue'
|
|
73
|
-
import type { RouteLocationRaw } from 'vue-router'
|
|
74
73
|
import { useNuxtApp } from '#app'
|
|
75
74
|
|
|
76
75
|
type LocaleCode = string
|
|
@@ -124,6 +123,12 @@ const toggleDropdown = () => {
|
|
|
124
123
|
dropdownOpen.value = !dropdownOpen.value
|
|
125
124
|
}
|
|
126
125
|
|
|
126
|
+
const switchLocaleRoute = (code: string) => {
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
return $switchLocaleRoute(code)
|
|
130
|
+
}
|
|
131
|
+
|
|
127
132
|
const localeLabel = (locale: Locale) => {
|
|
128
133
|
const current = props.customLabels[locale.code] || locale.displayName
|
|
129
134
|
if (!current) {
|
|
@@ -12,7 +12,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
12
12
|
const route = useRoute();
|
|
13
13
|
const locale = unref($getLocale());
|
|
14
14
|
const routeName = (route.name ?? "").toString();
|
|
15
|
-
const currentLocale = unref($getLocales().find((
|
|
15
|
+
const currentLocale = unref($getLocales().find((loc) => loc.code === locale));
|
|
16
16
|
if (!currentLocale) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getQuery, getCookie } from "h3";
|
|
2
|
+
import { useTranslationHelper } from "./translationHelper.js";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
async function fetchTranslations(locale) {
|
|
5
|
+
try {
|
|
6
|
+
const translations = await $fetch(`/_locales/general/${locale}/data.json`);
|
|
7
|
+
return translations;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
console.error(`Error loading translation for locale "${locale}":`, error);
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const useTranslationServerMiddleware = async (event, currentLocale) => {
|
|
14
|
+
const { getTranslation, loadTranslations, hasGeneralTranslation } = useTranslationHelper();
|
|
15
|
+
const runtimeI18n = useRuntimeConfig().public.i18nConfig;
|
|
16
|
+
const locale = (currentLocale || event.context.params?.locale || getQuery(event)?.locale || getCookie(event, "user-locale") || event.headers.get("accept-language")?.split(",")[0] || runtimeI18n.defaultLocale || "en").toString();
|
|
17
|
+
if (!hasGeneralTranslation(locale)) {
|
|
18
|
+
const translations = await fetchTranslations(locale);
|
|
19
|
+
await loadTranslations(locale, translations);
|
|
20
|
+
}
|
|
21
|
+
function t(key) {
|
|
22
|
+
const translation = getTranslation(locale, "index", key);
|
|
23
|
+
return translation ?? key;
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.",
|
|
5
5
|
"repository": "s00d/nuxt-i18n-micro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dev:build": "nuxi build playground",
|
|
46
46
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
47
47
|
"dev:generate": "nuxi generate playground",
|
|
48
|
-
"release": "npm run lint && npm run typecheck && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
48
|
+
"release": "npm run lint && npm run typecheck && npm run test && npm run test:types && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
49
49
|
"lint": "eslint .",
|
|
50
50
|
"lint:fix": "eslint . --fix",
|
|
51
51
|
"test": "playwright test",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"f4f9b29e-c87c-4731-99e1-f8100be361c1","timestamp":1732980443401,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|