@yiiamee/multilinguist 1.2.3 → 1.2.5
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.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPlugin, addImportsDir
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
@@ -26,7 +26,31 @@ function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, localesPath, outPath)
|
|
|
26
26
|
...keys.map((key) => ` ${JSON.stringify(key)}: string;`),
|
|
27
27
|
`}`,
|
|
28
28
|
``,
|
|
29
|
-
`export type LocaleKey = keyof TranslationMessages
|
|
29
|
+
`export type LocaleKey = keyof TranslationMessages;`,
|
|
30
|
+
``,
|
|
31
|
+
`declare module '#app' {`,
|
|
32
|
+
` interface NuxtApp {`,
|
|
33
|
+
" $t: (key: LocaleKey, variables?: Record<string, string>) => string;",
|
|
34
|
+
` }`,
|
|
35
|
+
`}`,
|
|
36
|
+
``,
|
|
37
|
+
`declare module 'vue' {`,
|
|
38
|
+
` interface ComponentCustomProperties {`,
|
|
39
|
+
" $t: (key: LocaleKey, variables?: Record<string, string>) => string;",
|
|
40
|
+
` }`,
|
|
41
|
+
`}`,
|
|
42
|
+
``,
|
|
43
|
+
`declare module '#app' {`,
|
|
44
|
+
` interface NuxtApp {`,
|
|
45
|
+
" t: (key: LocaleKey, variables?: Record<string, string>) => string;",
|
|
46
|
+
` }`,
|
|
47
|
+
`}`,
|
|
48
|
+
``,
|
|
49
|
+
`declare module 'vue' {`,
|
|
50
|
+
` interface ComponentCustomProperties {`,
|
|
51
|
+
" t: (key: LocaleKey, variables?: Record<string, string>) => string;",
|
|
52
|
+
` }`,
|
|
53
|
+
`}`
|
|
30
54
|
].join("\n");
|
|
31
55
|
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
32
56
|
fs.writeFileSync(outPath, output, "utf-8");
|
|
@@ -49,43 +73,22 @@ const module = defineNuxtModule({
|
|
|
49
73
|
meta: {
|
|
50
74
|
name: "@yiiamee/multilinguist",
|
|
51
75
|
configKey: "multilinguist",
|
|
52
|
-
version: "
|
|
76
|
+
version: "1.2.5",
|
|
53
77
|
compatibility: {
|
|
54
|
-
nuxt: "^3.
|
|
78
|
+
nuxt: "^3.0.0"
|
|
55
79
|
}
|
|
56
80
|
},
|
|
57
81
|
setup(moduleOptions, nuxtApp) {
|
|
58
82
|
const resolver = createResolver(import.meta.url);
|
|
59
83
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
60
84
|
addImportsDir(resolver.resolve("runtime/composables"));
|
|
61
|
-
addTypeTemplate({
|
|
62
|
-
filename: "types/multilinguist.d.ts",
|
|
63
|
-
getContents: () => `
|
|
64
|
-
import type { TranslationMessages } from './generated-locales'
|
|
65
|
-
|
|
66
|
-
declare module '#app' {
|
|
67
|
-
interface NuxtApp {
|
|
68
|
-
$t: (key: keyof TranslationMessages) => string
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare module 'vue' {
|
|
73
|
-
interface ComponentCustomProperties {
|
|
74
|
-
$t: (key: keyof TranslationMessages) => string
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
`
|
|
78
|
-
});
|
|
79
85
|
nuxtApp.hook("vite:extendConfig", (viteConfig) => {
|
|
80
86
|
viteConfig.plugins = viteConfig.plugins || [];
|
|
81
|
-
viteConfig.plugins.push(GenerateLocaleKeysPlugin(moduleOptions.defaultLocale, `${nuxtApp.options.rootDir}/public/locales`, resolver.resolve("./types/generated-locales.d.ts")));
|
|
87
|
+
viteConfig.plugins.push(GenerateLocaleKeysPlugin(moduleOptions.defaultLocale, `${nuxtApp.options.rootDir}/public/locales`, resolver.resolve("./runtime/types/generated-locales.d.ts")));
|
|
82
88
|
});
|
|
83
89
|
nuxtApp.hook("prepare:types", ({ references }) => {
|
|
84
90
|
references.push({
|
|
85
|
-
path: resolver.resolve("./types/generated-locales.d.ts")
|
|
86
|
-
});
|
|
87
|
-
references.push({
|
|
88
|
-
path: resolver.resolve("./types/multilinguist.d.ts")
|
|
91
|
+
path: resolver.resolve("./runtime/types/generated-locales.d.ts")
|
|
89
92
|
});
|
|
90
93
|
});
|
|
91
94
|
nuxtApp.options.runtimeConfig.public.multilinguist = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default function useMultilinguist(): {
|
|
2
|
-
t: (key: LocaleKey, variables?: Record<string, string>) => string;
|
|
2
|
+
t: (key: import("../types/generated-locales.js").LocaleKey, variables?: Record<string, string>) => string;
|
|
3
3
|
setLocale: (locale: string) => void;
|
|
4
4
|
initLocalization: () => Promise<void>;
|
|
5
5
|
locale: import("vue").Ref<string, string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
|
|
2
|
+
export interface TranslationMessages {
|
|
3
|
+
"Hello, World": string;
|
|
4
|
+
"Switch Locale": string;
|
|
5
|
+
"Paste your variable here": string;
|
|
6
|
+
"nested.Nested key": string;
|
|
7
|
+
"nested.Language": string;
|
|
8
|
+
"nested.nested second level.nested second level language": string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type LocaleKey = keyof TranslationMessages;
|
|
12
|
+
|
|
13
|
+
declare module '#app' {
|
|
14
|
+
interface NuxtApp {
|
|
15
|
+
$t: (key: LocaleKey, variables?: Record<string, string>) => string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module 'vue' {
|
|
20
|
+
interface ComponentCustomProperties {
|
|
21
|
+
$t: (key: LocaleKey, variables?: Record<string, string>) => string;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare module '#app' {
|
|
26
|
+
interface NuxtApp {
|
|
27
|
+
t: (key: LocaleKey, variables?: Record<string, string>) => string;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module 'vue' {
|
|
32
|
+
interface ComponentCustomProperties {
|
|
33
|
+
t: (key: LocaleKey, variables?: Record<string, string>) => string;
|
|
34
|
+
}
|
|
35
|
+
}
|