Zyme
Zyme
NNuxt
Created by Zyme on 1/15/2025 in #❓・help
Custom scripts in command line?
Is it possible to create a custom script that I can run with "npm run"? It seems I can't access defineNuxtConfig during this approach with a normal TS file and TSX. ReferenceError: defineNuxtConfig is not defined I want a custom script I can run in the terminal that extends "npm run generate" so I can pass some arguments.
12 replies
NNuxt
Created by Zyme on 1/10/2025 in #❓・help
defineNuxtRouteMiddleware not working
File is in middleware/nuxtRouteMiddleware.ts as docs imply.
export default defineNuxtRouteMiddleware(async (to) => {
console.log("Middleware running"); // Nothing is logged
});
export default defineNuxtRouteMiddleware(async (to) => {
console.log("Middleware running"); // Nothing is logged
});
This seems like a super simple use case, yet I can't even get it to console log?
16 replies
NNuxt
Created by Zyme on 1/9/2025 in #❓・help
Detecting locale using env variables not working
I am trying to get my multi domain locale detection working but it isn't. I don't want to use a prefix, it is different domains and I want to try out the translation in dev. I have:
nuxt.config.ts
const i18nDomains = ["mydomain.com", "mydomain.se"] as any;

...

i18n: {
vueI18n: "./i18n.config.ts",
multiDomainLocales: true,
lazy: true, // Lazy load translations
strategy: "no_prefix", // No prefix like "en" or "se" in routes
locales: [
{
code: "en",
domains: i18nDomains,
name: "English",
defaultForDomains: ["mydomain.com"],
},
{
code: "se",
domains: i18nDomains,
name: "Svenska",
defaultForDomains: ["mydomain.se"],
},
],
},
nuxt.config.ts
const i18nDomains = ["mydomain.com", "mydomain.se"] as any;

...

i18n: {
vueI18n: "./i18n.config.ts",
multiDomainLocales: true,
lazy: true, // Lazy load translations
strategy: "no_prefix", // No prefix like "en" or "se" in routes
locales: [
{
code: "en",
domains: i18nDomains,
name: "English",
defaultForDomains: ["mydomain.com"],
},
{
code: "se",
domains: i18nDomains,
name: "Svenska",
defaultForDomains: ["mydomain.se"],
},
],
},
Then I set the local using Powershell:
$env:DOMAIN_SE="mydomain.se" && npm run dev
$env:DOMAIN_SE="mydomain.se" && npm run dev
But it loads the english website and is looking for keys in the "en" locale:
[intlify] Not found 'Hello' key in 'en' locale messages
[intlify] Not found 'Hello' key in 'en' locale messages
And yes, this is true, it does not exist in "en" because "en" is the default language:
{{ $t("Hello") }}
{{ $t("Hello") }}
So how do I make it look in the "se" locale? And if the language is "en" I don't want to see this error message. I don't want to translate english to english. I want to use the full strings in the code instead of using translation keys. Lastly I need this to work with the generate command. So that I can get a translated website in static format in different languages.
5 replies