@anweb/nuxt-ancore 1.10.8 → 1.11.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/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.8",
4
+ "version": "1.11.0",
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,13 +1,28 @@
1
1
  import i18next from "i18next";
2
- import { getJSONHash } from "../utils/index.js";
2
+ import { useRuntimeConfig, useCookie } from "#app";
3
3
  export const useAnI18n = (resources) => {
4
- if (!resources) return { t: i18next.t };
5
- const ns = getJSONHash(resources);
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 };
20
+ const ns = JSON.stringify(resources);
6
21
  for (const lang in resources) {
7
22
  if (!i18next.hasResourceBundle(lang, ns)) {
8
23
  i18next.addResourceBundle(lang, ns, resources[lang]);
9
24
  }
10
25
  }
11
26
  const t = (key, options = {}) => i18next.t(key, { ns: [ns, "translation"], ...options });
12
- return { t };
27
+ return { t, ...returnObj };
13
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,9 @@ declare module 'nuxt/schema' {
12
12
  }
13
13
 
14
14
  interface PublicRuntimeConfig {
15
- i18n?: InitOptions<unknown>
15
+ i18n?: InitOptions<unknown> & {
16
+ cookie?: string
17
+ }
16
18
  }
17
19
  }
18
20
 
@@ -1,5 +1,4 @@
1
1
  export * from './asyncInit.js';
2
2
  export * from './coreApi.js';
3
- export * from './getJSONHash.js';
4
3
  export * from './toQuery.js';
5
4
  export * from './userApi.js';
@@ -1,5 +1,4 @@
1
1
  export * from "./asyncInit.js";
2
2
  export * from "./coreApi.js";
3
- export * from "./getJSONHash.js";
4
3
  export * from "./toQuery.js";
5
4
  export * from "./userApi.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.10.8",
3
+ "version": "1.11.0",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",
@@ -27,17 +27,17 @@
27
27
  "dev": "npm run dev:prepare && nuxi dev playground",
28
28
  "dev:build": "nuxi build playground",
29
29
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
30
- "release:patch": "npm run prepack && changelogen --patch --release && npm publish --access public && git push --follow-tags && changelogen gh release",
31
- "release:minor": "npm run prepack && changelogen --minor --release && npm publish --access public && git push --follow-tags && changelogen gh release",
32
- "release:major": "npm run prepack && changelogen --major --release && npm publish --access public && git push --follow-tags && changelogen gh release"
30
+ "release:patch": "npm run prepack && changelogen --patch --release && npm publish --access public && git push --follow-tags",
31
+ "release:minor": "npm run prepack && changelogen --minor --release && npm publish --access public && git push --follow-tags",
32
+ "release:major": "npm run prepack && changelogen --major --release && npm publish --access public && git push --follow-tags"
33
33
  },
34
34
  "dependencies": {
35
35
  "@nuxt/kit": "^4.1.2",
36
36
  "@vueuse/core": "^13.9.0",
37
37
  "@vueuse/integrations": "^13.9.0",
38
38
  "async-validator": "^4.2.5",
39
- "i18next": "^25.5.2",
40
- "js-sha256": "^0.11.1"
39
+ "hash-wasm": "^4.12.0",
40
+ "i18next": "^25.5.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@nuxt/devtools": "^2.6.3",
@@ -48,4 +48,4 @@
48
48
  "nuxt": "^4.1.2",
49
49
  "typescript": "~5.9.2"
50
50
  }
51
- }
51
+ }
@@ -1 +0,0 @@
1
- export declare const getJSONHash: (obj: object) => string;
@@ -1,5 +0,0 @@
1
- import { sha256 } from "js-sha256";
2
- export const getJSONHash = (obj) => {
3
- const json = JSON.stringify(obj);
4
- return sha256(json);
5
- };