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.
@@ -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},1732980454719,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f4f9b29e-c87c-4731-99e1-f8100be361c1",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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>
@@ -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},1732980454719,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f4f9b29e-c87c-4731-99e1-f8100be361c1",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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":"f4f9b29e-c87c-4731-99e1-f8100be361c1","timestamp":1732980443401}
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":[]}
@@ -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},1732980454719,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f4f9b29e-c87c-4731-99e1-f8100be361c1",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.34.1",
4
+ "version": "1.35.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
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="$switchLocaleRoute(locale.code) as RouteLocationRaw"
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((l) => l.code === locale));
15
+ const currentLocale = unref($getLocales().find((loc) => loc.code === locale));
16
16
  if (!currentLocale) {
17
17
  return;
18
18
  }
@@ -0,0 +1,2 @@
1
+ import type { H3Event } from 'h3';
2
+ export declare const useTranslationServerMiddleware: (event: H3Event, currentLocale?: string) => Promise<(key: string) => string>;
@@ -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.34.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":[]}