Closed harlan-zw closed 11 months ago
Hi, I have the same problem. Sorry to ask if already done, but do you have any solution to this? Any update about when this will be solved?
Many thanks!
Need this also :D Thank you for your work, that's one of the best packages I have used for Nuxt 3.
I think this might not be needed anymore in v3, if anyone can confirm.
I have a nuxt app with 3 locales (ca, en, es) after trying all three strategies i get:
prefix-> the sitemap shows only / and /en/ which is the default locale. prefix_and_default -> the sitemap shows only / prefix_except_default -> the sitemap shows only /
The update works much better with the content module, It's picking up all the locales! As for the rest I'm only getting the default route in the sitemap.
Using prefix_except_default
and exactly same experience as mentioned above.
Live sitemap picks up all content based routes with locales but other routes are ignored.
Example:
/blog
- Present
/ko/blog
- Missing
/zh/blog
- Missing
Here's my Configuration / repo
There were a few bugs found around how the i18n integration was working if you were using inline options, these are fixed in 3.0.15.
I've added a docs page for the i18n integration that may provide further help.
Any StackBlitz reproductions you can provide of things not working (you can use https://stackblitz.com/edit/nuxt-starter-jwuie4?file=app.vue as a starter), would be helpful :pray:
As of 3.1.3, the i18n logic has been updated:
Hi, I just try your last version (3.1.3), and the update apply about i18n integration are very nice !
I have just one question about include
and exclude
attributes:
When we use multiple custom sitemaps we need to define wich links are added into each sitemap with include
attribute. But with i18n, we need to add all locales availables into include
attribute like this:
sitemaps: {
main: {
include: [
'/en/auth/**', '/en/search/', '/en/privacy-policy', '/en',
'/fr/auth/**', '/fr/search/', '/fr/privacy-policy', '/fr'
]
},
versions: {
include: ['/en/version/**', '/fr/version/**']
},
information: {
include: ['/en/information/**', '/fr/information/**']
}
}
I don't kow if you can manage this case (with a marker for example) to have something like this:
sitemaps: {
main: {
include: ['/[locale]/auth/**', '/[locale]/search/', '/[locale]/privacy-policy', '/[locale]']
},
...
}
Or any other way to handle all locale automatically with include
(and exclude
) attributes.
I make this reproduction stackblitz of this use case.
As of 3.1.3, the i18n logic has been updated:
- will now correctly show all i18n URLs with all hreflangs
- x-default added for default lang
- hreflang will now use the locale iso if available (over the code).
Got it working with this version, all urls now showing up in sitemap! Thank you Harlan 🎉 😄
Hey everyone,
I'm having some issues with dynamic URLs. I cannot seem to find a solution that fixes my problem.
I'm using the i18n strategy prefix
and the dynamic URLs I'm injecting do not have any prefix.
If I consider adding them myself, then the alternative links are wrong and I'd prefer avoiding doing this myself anyway.
"@nuxtjs/i18n": "^8.0.0-beta.13",
"nuxt": "^3.6.5",
"nuxt-simple-sitemap": "^3.1.8",
// nuxt.config.ts
export default defineNuxtConfig({
// ...
i18n: {
strategy: 'prefix',
defaultLocale: 'en',
locales: [
{ code: 'fr', iso: 'fr' },
{ code: 'es', iso: 'es' },
{code: 'en', iso: 'en'}
],
},
site: {
url: 'http://localhost:3000',
},
sitemap: {
autoAlternativeLangPrefixes: true,
xsl: false
}
})
Entry for non-dynamic URL:
<url>
<lastmod>2023-08-03T09:13:24+00:00</lastmod>
<loc>http://localhost:3000/en/definitions</loc>
<xhtml:link rel="alternate" hreflang="fr" href="http://localhost:3000/fr/definitions" />
<xhtml:link rel="alternate" hreflang="es" href="http://localhost:3000/es/definitions" />
<xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/definitions" />
<xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3000/en/definitions" />
</url>
Entry for dynamic URL injected via server/api/_sitemap-urls.ts
<url>
<lastmod>2023-08-22T13:39:17+00:00</lastmod>
<loc>http://localhost:3000/definitions/river</loc>
<xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3000/definitions/river" />
<xhtml:link rel="alternate" hreflang="fr" href="http://localhost:3000/fr/definitions/river" />
<xhtml:link rel="alternate" hreflang="es" href="http://localhost:3000/es/definitions/river" />
<xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/definitions/river" />
</url>
The <loc>
is missing the prefix and the x-default
just also has a prefix.
Expected:
<url>
<lastmod>2023-08-22T13:39:17+00:00</lastmod>
<loc>http://localhost:3000/en/definitions/river</loc>
<xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3000/en/definitions/river" />
<xhtml:link rel="alternate" hreflang="fr" href="http://localhost:3000/fr/definitions/river" />
<xhtml:link rel="alternate" hreflang="es" href="http://localhost:3000/es/definitions/river" />
<xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/definitions/river" />
</url>
Am I missing something? Thanks for the help!
Thank you for the detailed post @vdlbk.
I've done some more work on i18n based on what you've sent. Please see the release notes https://github.com/harlan-zw/nuxt-simple-sitemap/releases/tag/v3.2.0
Hey @harlan-zw! Thanks for the quick reaction, I really appreciate it!
Using 3.2.0, I can change the value of sitemaps
to undefined | true | false
, it gives me every time hasDisabledSitemaps: true
. So it's generating the same sitemap with every link in it (Similar to the problem n°2 I'm mentioning below). With the 3.2.2, it seems to work better.
Still, I tried on Stackblitz and locally on my project, and I have on both the same problems.
When sitemaps === undefined
(or empty), no index sitemap is generated for each locale. Only the default. And we are missing the last updated date. Is that something to do with an i18n configuration now? I'm guessing not.
When sitemaps === false
, some entries are missing the last updated date, and there are wrong links. Looks like some of the locale prefixes are being mixed together sometimes. But we can also see some valid links.
Many thanks for your help and time! 🚀
Sorry @vdlbk, I tested this out by using locales as a string array (['en', fr']
) without testing for object entries ([{ code: 'en', iso: 'en-AU' }]
) :facepalm: Appreciate your screenshots!
Can you please try 3.2.4. I've tested it out on your StackBlitz repo and it looks correct (https://stackblitz.com/edit/nuxt-starter-kq6gnw?file=nuxt.config.ts)
No worries @harlan-zw, happy to see you spotted quickly the reason behind this!
But I'm curious to understand why we strip non-prefixed URLs instead of adding the prefix? Especially in the prefix strategy where we expect every URL to have a prefix. Does it means for dynamic URLs I should add the prefix myself?
And it does not look to work properly.
In the version 3.2.3, for my example with locales en and hr , we can see these 4 URLS : |
URL | Comment | valid? |
---|---|---|---|
http://localhost:3000/en/definitions | Non-dynamic URL | ✔️ | |
http://localhost:3000/definitions/river | Dynamic URL missing the locale prefix en |
🔴 | |
http://localhost:3000/hr/definitions | Non-dynamic URL | ✔️ | |
http://localhost:3000/hr/definitions/river | Dynamic URL with the locale prefix hr |
✔️ |
In the version 3.2.4, the http://localhost:3000/definitions/river
got stripped because it misses the prefix, while http://localhost:3000/hr/definitions/river
no. But as it is also a dynamic URL and has it "received" the prefix somehow, it's not stripped. Do you know why the default locale was not added to dynamic URLs?
Because if I change the defaultLocale
to hr
, then it's the opposite that happens, the en
URL is here and the hr
URL got removed.
The expected output should be the following URLs in the sitemap: | URL | Comment |
---|---|---|
http://localhost:3000/en | Non-dynamic URL | |
http://localhost:3000/hr | Non-dynamic URL | |
http://localhost:3000/en/definitions | Non-dynamic URL | |
http://localhost:3000/hr/definitions | Non-dynamic URL | |
http://localhost:3000/en/definitions/river | Dynamic URL with the locale prefix en |
|
http://localhost:3000/hr/definitions/river | Dynamic URL with the locale prefix hr |
|
http://localhost:3000/en/about | Non-dynamic URL | |
http://localhost:3000/hr/about | Non-dynamic URL |
Also, do you know why some entries are missing the last update date?
Adding the defaults
configuration does not change the deal.
Nice, almost there :crossed_fingers: 3.2.5 is looking better but maybe you can confirm
https://stackblitz.com/edit/nuxt-starter-kq6gnw?file=package.json
It's working as expected. It's neat! Well done @harlan-zw, you did a great job here! 👏
Thank you for your amazing help @vdlbk!
I'll keep this open while there's still some outstanding i18n issues.
there isn't a compostable that i can use to set dynamic custom alternative language directly on the page? I have a blog but the articles URL are different for every lang Example:
// blog section
en/blog/a-simple-article
it/blog/un-semplice-articolo
de/blog/een-eenvoudig-artikel
// guide section
en/guide/a-simple-guide
it/guide/una-semplice-guide
de/guide/een-eenvoudig-handleiding
// case-study section
en/case-study/a-simple-post
it/case-study/un-semplice-post
de/case-study/een-eenvoudig-post
What's the best practice to implement alternate langs in this case?
@harlan-zw I was using nuxt-seo-kit and it was not the version 3 for nuxt-simple-sitemap.
https://github.com/harlan-zw/nuxt-seo-kit/blob/main/layer/package.json
@LeCoupa are you using @nuxtseo/module
v2.0.0-beta
?
@dargmuesli I am using nuxt-seo-kit@1.3.9
. Maybe, that's why?
EDIT: I ended up removing @nuxtseo/module
and using directly nuxt-simple-robots
and nuxt-simple-sitemap
.
@luca-smartpricing I am facing the same problem, Could you solve it?
there isn't a compostable that i can use to set dynamic custom alternative language directly on the page? I have a blog but the articles URL are different for every lang Example:
// blog section en/blog/a-simple-article it/blog/un-semplice-articolo de/blog/een-eenvoudig-artikel // guide section en/guide/a-simple-guide it/guide/una-semplice-guide de/guide/een-eenvoudig-handleiding // case-study section en/case-study/a-simple-post it/case-study/un-semplice-post de/case-study/een-eenvoudig-post
What's the best practice to implement alternate langs in this case?
You can use the i18n.pages
config or the defineI18n
composable, just make sure you set the strategy to no_prefix
I think
Hi 👋
I'm having some issues with i18n support. Please find below a partial from my en-US-sitemap.xml
. Notice the lines marked with ❌, these urls/pages do not exist. I've been using Vue for years but its my first time using Nuxt and this sitemap package, so its totally possible I am doing something silly.
Fwiw the blog articles are coming from nuxt/content and slugs are localized /blog/article-two
in English language would be /es/blog/article-two-es
in Spanish language..
<url>
<lastmod>2023-10-17T22:19:43+00:00</lastmod>
✅ <loc>http://localhost:3001/blog/article-two</loc>
✅ <xhtml:link rel="alternate" hreflang="en-US" href="http://localhost:3001/blog/article-two" />
❌ <xhtml:link rel="alternate" hreflang="es-ES" href="http://localhost:3001/es/blog/article-two" />
❌ <xhtml:link rel="alternate" hreflang="nl-NL" href="http://localhost:3001/nl/blog/article-two" />
✅ <xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3001/blog/article-two" />
</url>
<url>
<lastmod>2023-10-17T22:31:15+00:00</lastmod>
❌ <loc>http://localhost:3001/blog/article-two-es</loc>
❌ <xhtml:link rel="alternate" hreflang="en-US" href="http://localhost:3001/blog/article-two-es" />
✅ <xhtml:link rel="alternate" hreflang="es-ES" href="http://localhost:3001/es/blog/article-two-es" />
❌ <xhtml:link rel="alternate" hreflang="nl-NL" href="http://localhost:3001/nl/blog/article-two-es" />
❌ <xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3001/blog/article-two-es" />
</url>
<url>
<lastmod>2023-10-17T22:31:15+00:00</lastmod>
❌ <loc>http://localhost:3001/blog/article-two-nl</loc>
❌ <xhtml:link rel="alternate" hreflang="en-US" href="http://localhost:3001/blog/article-two-nl" />
❌ <xhtml:link rel="alternate" hreflang="es-ES" href="http://localhost:3001/es/blog/article-two-nl" />
✅ <xhtml:link rel="alternate" hreflang="nl-NL" href="http://localhost:3001/nl/blog/article-two-nl" />
❌ <xhtml:link rel="alternate" hreflang="x-default" href="http://localhost:3001/blog/article-two-nl" />
</url>
This is the i18n package in my deps.
npm:@nuxtjs/i18n-edge@^8.0.0-rc.4-28265986.9dae464
// nuxt.config.js
sitemap: {
autoI18n: true,
strictNuxtContentPaths: true,
discoverImages: false,
},
If I set autoI18n: false
I get a single sitemap.xml
with all urls including proper i18n paths which actually is perfectly fine, perhaps I should just not use autoI18n
..
Thank you for the efforts! 🙌
我的i18n设置了domain模式,在这种情况下启用autoI18n,sitemap中不能得到正确的网页地址。
There is a problem where I want to set up a sitemap using the dynamic URLs feature, and the URLs are different in different languages, how to avoid generating all versions of this URL?
In the v4 release there have been many more improvements to i18n. I've updated the i18n documentation here.
I'm going to close this issue off as I believe all major issues are solved, anything further will just be proper documentation.
Please let me know if you have any problems with a new issue and I'll do my best to help.
Clear and concise description of the problem
i18n support is quite complicated, there's many edge cases and moving parts.
This issue will be used to track general i18n support, including support for all i18n strategies.