@yiiamee/multilinguist 1.2.7 → 1.2.8
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
|
@@ -11,6 +11,44 @@ function flattenKeys(obj, prefix = "") {
|
|
|
11
11
|
return [fullKey];
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
+
const generateOutputString = (func) => {
|
|
15
|
+
return `
|
|
16
|
+
// AUTO-GENERATED FILE \u2014 DO NOT EDIT MANUALLY
|
|
17
|
+
|
|
18
|
+
export interface TranslationMessages {
|
|
19
|
+
${func()}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type LocaleKey = keyof TranslationMessages;
|
|
23
|
+
|
|
24
|
+
export type TFunction = <K extends LocaleKey>(
|
|
25
|
+
key: K,
|
|
26
|
+
variables?: Record<string, string>
|
|
27
|
+
) => string;
|
|
28
|
+
|
|
29
|
+
declare global {
|
|
30
|
+
type LocaleKey = keyof TranslationMessages;
|
|
31
|
+
type TFunction = <K extends LocaleKey>(
|
|
32
|
+
key: K,
|
|
33
|
+
variables?: Record<string, string>
|
|
34
|
+
) => string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare module '#app' {
|
|
38
|
+
interface NuxtApp {
|
|
39
|
+
$t: TFunction;
|
|
40
|
+
t: TFunction;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module 'vue' {
|
|
45
|
+
interface ComponentCustomProperties {
|
|
46
|
+
$t: TFunction;
|
|
47
|
+
t: TFunction;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
};
|
|
14
52
|
function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, localesPath, outPath) {
|
|
15
53
|
async function generateTypes() {
|
|
16
54
|
const defaultLocalePath = path.join(localesPath, `${defaultLocaleFromConfig}.json`);
|
|
@@ -20,29 +58,7 @@ function GenerateLocaleKeysPlugin(defaultLocaleFromConfig, localesPath, outPath)
|
|
|
20
58
|
}
|
|
21
59
|
const json = JSON.parse(fs.readFileSync(defaultLocalePath, "utf-8"));
|
|
22
60
|
const keys = flattenKeys(json);
|
|
23
|
-
const output =
|
|
24
|
-
`// AUTO-GENERATED FILE \u2014 DO NOT EDIT MANUALLY`,
|
|
25
|
-
`export interface TranslationMessages {`,
|
|
26
|
-
...keys.map((key) => ` ${JSON.stringify(key)}: string;`),
|
|
27
|
-
`}`,
|
|
28
|
-
``,
|
|
29
|
-
`export type LocaleKey = keyof TranslationMessages;`,
|
|
30
|
-
``,
|
|
31
|
-
`declare module '#app' {`,
|
|
32
|
-
` interface NuxtApp {`,
|
|
33
|
-
" $t<const K extends LocaleKey>(key: K, variables?: Record<string, string>): string; ",
|
|
34
|
-
" t<const K extends LocaleKey>(key: K, variables?: Record<string, string>): string; ",
|
|
35
|
-
` }`,
|
|
36
|
-
`}`,
|
|
37
|
-
``,
|
|
38
|
-
`declare module 'vue' {`,
|
|
39
|
-
` interface ComponentCustomProperties {`,
|
|
40
|
-
" $t<const K extends LocaleKey>(key: K, variables?: Record<string, string>): string; ",
|
|
41
|
-
" t<const K extends LocaleKey>(key: K, variables?: Record<string, string>): string; ",
|
|
42
|
-
` }`,
|
|
43
|
-
`}`,
|
|
44
|
-
``
|
|
45
|
-
].join("\n");
|
|
61
|
+
const output = generateOutputString(() => keys.map((key) => ` ${JSON.stringify(key)}: string;`).join("\n"));
|
|
46
62
|
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
47
63
|
fs.writeFileSync(outPath, output, "utf-8");
|
|
48
64
|
console?.warn(`\u2705 Generated types to ${outPath} from ${defaultLocalePath}`);
|
|
@@ -64,7 +80,7 @@ const module = defineNuxtModule({
|
|
|
64
80
|
meta: {
|
|
65
81
|
name: "@yiiamee/multilinguist",
|
|
66
82
|
configKey: "multilinguist",
|
|
67
|
-
version: "1.2.
|
|
83
|
+
version: "1.2.8",
|
|
68
84
|
compatibility: {
|
|
69
85
|
nuxt: "^3.0.0"
|
|
70
86
|
}
|
|
@@ -75,7 +91,13 @@ const module = defineNuxtModule({
|
|
|
75
91
|
addImportsDir(resolver.resolve("runtime/composables"));
|
|
76
92
|
nuxtApp.hook("vite:extendConfig", (viteConfig) => {
|
|
77
93
|
viteConfig.plugins = viteConfig.plugins || [];
|
|
78
|
-
viteConfig.plugins.push(
|
|
94
|
+
viteConfig.plugins.push(
|
|
95
|
+
GenerateLocaleKeysPlugin(
|
|
96
|
+
moduleOptions.defaultLocale,
|
|
97
|
+
`${nuxtApp.options.rootDir}/public/locales`,
|
|
98
|
+
resolver.resolve("./runtime/types/generated-locales.d.ts")
|
|
99
|
+
)
|
|
100
|
+
);
|
|
79
101
|
});
|
|
80
102
|
nuxtApp.hook("prepare:types", ({ references }) => {
|
|
81
103
|
references.push({
|
|
@@ -4,7 +4,7 @@ export type TranslationMap = readonly string[];
|
|
|
4
4
|
export type Locale<T extends TranslationMap> = T[number];
|
|
5
5
|
export type LocaleKeys<T extends TranslationMap> = T[keyof T];
|
|
6
6
|
export type TMultilinguistResponse<T extends TranslationMap> = {
|
|
7
|
-
t<
|
|
7
|
+
t<K extends LocaleKey>(key: K, variables?: Record<string, string>): string;
|
|
8
8
|
setLocale: (locale: Locale<T>) => void;
|
|
9
9
|
initLocalization: () => Promise<void>;
|
|
10
10
|
locale: Ref<Locale<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default function useMultilinguist(): {
|
|
2
|
-
t<
|
|
2
|
+
t<K extends LocaleKey>(key: K, variables?: Record<string, string>): string;
|
|
3
3
|
setLocale: (locale: string) => void;
|
|
4
4
|
initLocalization: () => Promise<void>;
|
|
5
5
|
locale: import("vue").Ref<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yiiamee/multilinguist",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Nuxt 3 Multilinguist Localization module",
|
|
5
5
|
"repository": "yiiameeMich/multilinguist",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,9 +14,21 @@
|
|
|
14
14
|
},
|
|
15
15
|
"types": "./dist/types.d.mts",
|
|
16
16
|
"files": [
|
|
17
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"runtime/types"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"localization",
|
|
22
|
+
"nuxt localization",
|
|
23
|
+
"nuxt",
|
|
24
|
+
"internationalization",
|
|
25
|
+
"languages",
|
|
26
|
+
"locales",
|
|
27
|
+
"translation",
|
|
28
|
+
"localization nuxt",
|
|
29
|
+
"translation nuxt",
|
|
30
|
+
"nuxt translation"
|
|
18
31
|
],
|
|
19
|
-
"keywords": ["localization", "nuxt localization", "nuxt", "internationalization", "languages", "locales", "translation"],
|
|
20
32
|
"bugs": {
|
|
21
33
|
"email": "michaelkukh.dev@gmail.com"
|
|
22
34
|
},
|
|
@@ -36,7 +48,10 @@
|
|
|
36
48
|
"nuxt": "^3.0.0"
|
|
37
49
|
},
|
|
38
50
|
"dependencies": {
|
|
39
|
-
"@nuxt/kit": "^3.17.4"
|
|
51
|
+
"@nuxt/kit": "^3.17.4",
|
|
52
|
+
"eslint-config-prettier": "^10.1.5",
|
|
53
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
54
|
+
"prettier": "^3.5.3"
|
|
40
55
|
},
|
|
41
56
|
"devDependencies": {
|
|
42
57
|
"@nuxt/devtools": "^2.4.1",
|