nuxt-i18n-micro 1.34.1 → 1.35.1
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/e0ff356c-21be-41f8-ae56-03da9bfbdd59.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -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},1733170121034,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"e0ff356c-21be-41f8-ae56-03da9bfbdd59",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},1733170121034,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"e0ff356c-21be-41f8-ae56-03da9bfbdd59",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"e0ff356c-21be-41f8-ae56-03da9bfbdd59","timestamp":1733170108539}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"e0ff356c-21be-41f8-ae56-03da9bfbdd59","timestamp":1733170108539,"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},1733170121034,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"e0ff356c-21be-41f8-ae56-03da9bfbdd59",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import fs__default, { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { useNuxt, defineNuxtModule, useLogger, createResolver, addTemplate, addPlugin, addImportsDir, addServerHandler, addComponentsDir, addTypeTemplate, extendPages, addPrerenderRoutes } from '@nuxt/kit';
|
|
5
6
|
import { watch } from 'chokidar';
|
|
6
7
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
@@ -453,6 +454,11 @@ const module = defineNuxtModule({
|
|
|
453
454
|
write: true,
|
|
454
455
|
getContents: () => `export const plural = ${options.plural.toString()};`
|
|
455
456
|
});
|
|
457
|
+
addTemplate({
|
|
458
|
+
filename: "i18n.config.mjs",
|
|
459
|
+
write: true,
|
|
460
|
+
getContents: () => `export const defaultLocale = "${options.defaultLocale}";`
|
|
461
|
+
});
|
|
456
462
|
const apiBaseUrl = (process.env.NUXT_I18N_APP_BASE_URL ?? options.apiBaseUrl ?? "_locales").replace(/^\/+|\/+$|\/{2,}/, "");
|
|
457
463
|
nuxt.options.runtimeConfig.public.i18nConfig = {
|
|
458
464
|
plural: void 0,
|
|
@@ -589,6 +595,13 @@ const module = defineNuxtModule({
|
|
|
589
595
|
addPrerenderRoutes(prerenderRoutes);
|
|
590
596
|
});
|
|
591
597
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
598
|
+
if (nitroConfig.imports) {
|
|
599
|
+
nitroConfig.imports.presets = nitroConfig.imports.presets || [];
|
|
600
|
+
nitroConfig.imports.presets.push({
|
|
601
|
+
from: fileURLToPath(new URL("./runtime/translation-server-middleware.ts", import.meta.url)),
|
|
602
|
+
imports: ["useTranslationServerMiddleware"]
|
|
603
|
+
});
|
|
604
|
+
}
|
|
592
605
|
const routes = nitroConfig.prerender?.routes || [];
|
|
593
606
|
nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
|
|
594
607
|
const pages = nuxt.options.generate.routes || [];
|
|
@@ -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.1",
|
|
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:types && npm run test && 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":[]}
|