@anweb/nuxt-ancore 1.10.9 → 1.11.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/module.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { InitOptions } from 'i18next';
2
+ import { PublicRuntimeConfig } from 'nuxt/schema';
3
3
 
4
4
  interface ModuleOptions {
5
5
  api?: string;
6
- i18n?: InitOptions<unknown>;
6
+ i18n?: PublicRuntimeConfig['i18n'];
7
7
  }
8
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
9
9
 
package/dist/module.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { InitOptions } from 'i18next';
2
+ import { PublicRuntimeConfig } from 'nuxt/schema';
3
3
 
4
4
  interface ModuleOptions {
5
5
  api?: string;
6
- i18n?: InitOptions<unknown>;
6
+ i18n?: PublicRuntimeConfig['i18n'];
7
7
  }
8
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
9
9
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.10.9",
4
+ "version": "1.11.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,5 +1,9 @@
1
1
  export declare const useAnI18n: (resources?: Record<string, any>) => {
2
+ lang: string;
3
+ set: (lang: string) => void;
2
4
  t: import("i18next").TFunction<["translation", ...string[]], undefined>;
3
5
  } | {
6
+ lang: string;
7
+ set: (lang: string) => void;
4
8
  t: (key: string, options?: {}) => string;
5
9
  };
@@ -1,6 +1,22 @@
1
1
  import i18next from "i18next";
2
+ import { useRuntimeConfig, useCookie } from "#app";
2
3
  export const useAnI18n = (resources) => {
3
- if (!resources) return { t: i18next.t };
4
+ const returnObj = {
5
+ lang: i18next.language,
6
+ set: (lang) => {
7
+ const config = useRuntimeConfig().public.i18n;
8
+ if (config?.cookie) {
9
+ const cookie = useCookie(config?.cookie, {
10
+ maxAge: 60 * 60 * 24 * 365,
11
+ path: "/",
12
+ sameSite: "lax",
13
+ secure: true
14
+ });
15
+ cookie.value = lang;
16
+ }
17
+ }
18
+ };
19
+ if (!resources) return { t: i18next.t, ...returnObj };
4
20
  const ns = JSON.stringify(resources);
5
21
  for (const lang in resources) {
6
22
  if (!i18next.hasResourceBundle(lang, ns)) {
@@ -8,5 +24,5 @@ export const useAnI18n = (resources) => {
8
24
  }
9
25
  }
10
26
  const t = (key, options = {}) => i18next.t(key, { ns: [ns, "translation"], ...options });
11
- return { t };
27
+ return { t, ...returnObj };
12
28
  };
@@ -1,7 +1,11 @@
1
1
  import i18next from "i18next";
2
- import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
+ import { defineNuxtPlugin, useRuntimeConfig, useCookie } from "#app";
3
3
  export default defineNuxtPlugin(async () => {
4
- const config = useRuntimeConfig().public.i18n;
4
+ const config = { ...useRuntimeConfig().public.i18n };
5
5
  if (!config) return;
6
+ if (config.cookie) {
7
+ config.lng = useCookie(config.cookie).value || config.lng;
8
+ delete config.cookie;
9
+ }
6
10
  await i18next.init(config);
7
11
  });
@@ -12,7 +12,10 @@ declare module 'nuxt/schema' {
12
12
  }
13
13
 
14
14
  interface PublicRuntimeConfig {
15
- i18n?: InitOptions<unknown>
15
+ i18n?: InitOptions<unknown> & {
16
+ cookie?: string
17
+ resources?: Record<string, { translation: Record<string, string> | string }>
18
+ }
16
19
  }
17
20
  }
18
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.10.9",
3
+ "version": "1.11.1",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",