@yassidev/nuxt-directus 0.0.7 → 0.0.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
|
@@ -3,6 +3,7 @@ import { generateDirectusTypes } from 'directus-sdk-typegen';
|
|
|
3
3
|
import { fetchTranslations, syncTranslations } from '../dist/runtime/server.js';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { NAME } from '../dist/runtime/constants.js';
|
|
6
|
+
import { join } from 'node:path';
|
|
6
7
|
|
|
7
8
|
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
8
9
|
function hasTrailingSlash(input = "", respectQueryAndFragment) {
|
|
@@ -183,30 +184,38 @@ function setupI18n(config, nuxt, logger) {
|
|
|
183
184
|
accessToken: config.accessToken,
|
|
184
185
|
i18nPrefix: config.i18n.prefix
|
|
185
186
|
};
|
|
187
|
+
const path = "directus/locales";
|
|
188
|
+
const dirPath = resolve(nuxt.options.buildDir, path);
|
|
189
|
+
nuxt.options.watch.push(join(dirPath, "**"));
|
|
190
|
+
nuxt.options.vite.server = defu(nuxt.options.vite.server, {
|
|
191
|
+
watch: {
|
|
192
|
+
ignored: [`!${join(dirPath, "**")}`]
|
|
193
|
+
}
|
|
194
|
+
});
|
|
186
195
|
codes.map((code) => {
|
|
187
196
|
const { dst } = addTemplate({
|
|
188
197
|
write: true,
|
|
189
|
-
filename:
|
|
198
|
+
filename: `${path}/${code}.json`,
|
|
190
199
|
getContents: () => fetchTranslations(code, runtimeConfig).then((translations) => {
|
|
191
200
|
return JSON.stringify(Object.fromEntries(translations.map((translation) => [translation.key, translation.value])), null, 2);
|
|
192
201
|
})
|
|
193
202
|
});
|
|
194
|
-
nuxt.hook("builder:watch", async (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
203
|
+
nuxt.hook("builder:watch", async (_, filePath) => {
|
|
204
|
+
console.log("filePath", filePath, dst);
|
|
205
|
+
if (filePath !== dst) return;
|
|
206
|
+
const translations = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
207
|
+
const done = await syncTranslations(code, translations, runtimeConfig);
|
|
208
|
+
if (!done) return;
|
|
209
|
+
logger.info(`Synced translations for locale: ${code}`);
|
|
201
210
|
});
|
|
202
211
|
});
|
|
203
212
|
}
|
|
204
213
|
nuxt.hook("i18n:registerModule", (register) => {
|
|
205
214
|
const locales = codes.map((code) => ({
|
|
206
215
|
code,
|
|
207
|
-
file: "index
|
|
216
|
+
file: resolve("./runtime/lang/index")
|
|
208
217
|
}));
|
|
209
|
-
register({ langDir:
|
|
218
|
+
register({ langDir: "", locales });
|
|
210
219
|
logger.success("Locales have been registered: " + codes.join(", "));
|
|
211
220
|
});
|
|
212
221
|
}
|
package/dist/runtime/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Use directus (rest)
|
|
3
3
|
*/
|
|
4
|
-
export declare function useDirectus(): import("@directus/sdk").DirectusClient<
|
|
4
|
+
export declare function useDirectus(): import("@directus/sdk").DirectusClient<Schema> & import("@directus/sdk").GraphqlClient<Schema>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Use directus (rest)
|
|
3
3
|
*/
|
|
4
|
-
export declare function useDirectus(): import("@directus/sdk").DirectusClient<
|
|
4
|
+
export declare function useDirectus(): import("@directus/sdk").DirectusClient<Schema> & import("@directus/sdk").RestClient<Schema>;
|