@yiiamee/multilinguist 1.6.0 → 1.6.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/README.md CHANGED
@@ -31,7 +31,7 @@ export default defineNuxtConfig({
31
31
  })
32
32
  ```
33
33
 
34
- Then, create a "locales" directory in /public directory. This is necessary for module to access your languages.
34
+ Then, create a "locales" directory in root directory of your project.
35
35
 
36
36
  ![directory_structure.png](directory_structure.png)
37
37
 
@@ -82,6 +82,24 @@ export default defineNuxtConfig({
82
82
  })
83
83
  ```
84
84
 
85
+ Also, if you want to use a different folder name for your locales' files, or you want to specify other path to the directory, you can set the `localesPath` option in your nuxt.config:
86
+
87
+ ```nuxt.config.ts
88
+ export default defineNuxtConfig({
89
+ modules: [
90
+ "@yiiamee/multilinguist",
91
+ ],
92
+ multilinguist: {
93
+ defaultLocale: "en",
94
+ supportedLanguages: ["en", "es"],
95
+ logging: false,
96
+ setBrowserLanguage: false, // by default: true
97
+ localesPath: "./languages", // by default: "./locales"
98
+ },
99
+ })
100
+ ```
101
+
102
+ ### Important! Keep in mind, that it is not recommended to use "public" folder for your locales' files, as it may lead to rendering, security and other issues.
85
103
 
86
104
  # Usage
87
105
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yiiamee/multilinguist",
3
3
  "configKey": "multilinguist",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0 || ^4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -49,10 +49,9 @@ declare module 'vue' {
49
49
  }
50
50
  `;
51
51
  };
52
- function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, localesPath, outPath, logging = true) {
52
+ function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, absoluteLocalesPath, outPath, logging = true) {
53
53
  async function generateTypes() {
54
- const defaultLocalePath = path.join(localesPath, `${defaultLocaleFromConfig}.json`);
55
- console.log(defaultLocalePath);
54
+ const defaultLocalePath = path.join(absoluteLocalesPath, `${defaultLocaleFromConfig}.json`);
56
55
  if (!fs.existsSync(defaultLocalePath)) {
57
56
  console?.error(`\u274C Default locale file not found: ${defaultLocalePath}`);
58
57
  return;
@@ -72,7 +71,7 @@ function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, localesPath, outPath,
72
71
  await generateTypes();
73
72
  },
74
73
  async handleHotUpdate(ctx) {
75
- if (ctx.file.endsWith(".json") && ctx.file.includes(localesPath)) {
74
+ if (ctx.file.endsWith(".json") && ctx.file.includes(absoluteLocalesPath)) {
76
75
  await generateTypes();
77
76
  }
78
77
  }
@@ -83,7 +82,7 @@ const module = defineNuxtModule({
83
82
  meta: {
84
83
  name: "@yiiamee/multilinguist",
85
84
  configKey: "multilinguist",
86
- version: "1.6.0",
85
+ version: "1.6.1",
87
86
  compatibility: {
88
87
  nuxt: "^3.0.0 || ^4.0.0"
89
88
  },
@@ -1,4 +1,4 @@
1
- import { type Ref, type ComputedRef } from "vue";
1
+ import { type ComputedRef, type Ref } from "vue";
2
2
  import type { LocaleKey } from "../types/generated-locales.js";
3
3
  export type TranslationMap = readonly string[];
4
4
  export type Locale<T extends TranslationMap> = T[number];
@@ -27,7 +27,7 @@ export default function useLocalization(supportedLanguages, defaultLocale, setBr
27
27
  const userPrefferableLocale = computed(() => {
28
28
  return userSelectedLocale.value ? userSelectedLocale.value : userBrowserLocale.value;
29
29
  });
30
- const locale = useState(() => {
30
+ const locale = useState("current-locale-multilinguist", () => {
31
31
  return userPrefferableLocale.value || defaultLocale;
32
32
  });
33
33
  const t = (key, variables) => {
@@ -1,8 +1,30 @@
1
1
  export declare const localeFiles: {
2
2
  "/locales/en.json": {
3
- default: any;
3
+ default: {
4
+ "Hello, World": string;
5
+ "Switch Locale": string;
6
+ "Paste your variable here": string;
7
+ nested: {
8
+ "Nested key": string;
9
+ Language: string;
10
+ "nested second level": {
11
+ "nested second level language": string;
12
+ };
13
+ };
14
+ };
4
15
  };
5
16
  "/locales/es.json": {
6
- default: any;
17
+ default: {
18
+ "Hello, World": string;
19
+ "Switch Locale": string;
20
+ "Paste your variable here": string;
21
+ nested: {
22
+ "Nested key": string;
23
+ Language: string;
24
+ "nested second level": {
25
+ "nested second level language": string;
26
+ };
27
+ };
28
+ };
7
29
  };
8
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiiamee/multilinguist",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Nuxt Multilinguist module for localizations",
5
5
  "repository": "yiiameeMich/multilinguist",
6
6
  "license": "MIT",