As an extension on wintercms/winter#1421, I would like to add a new language nl.
Plot twist, I already have
- mydomain.be/nl
- mydomain.be/en
- mydomain.be/fr
for mydomain.nl I want to use a new language nl.
since nl already exists, it should be nl-NL.
But we don't want the url mydomain.nl/nl-NL. We want mydomain.nl/nl to serve the nl-NL language and mydomain.be/nl to serve the 'nl' language (or renamed to nl-BE).
See this as if you want to serve different words for UK and USA (trousers <=> pants).
- mydomain.nl/nl (nl-NL translations)
- mydomain.nl/en (same translations as mydomain.be/en)
- mydomain.nl/fr (same translations as mydomain.be/fr)
I tried this code, which seems to work at first glance but other problems arise on the wn-sitemap-plugin (and maybe elsewhere).
The nl-NL shows up on the sitemap, but the URL shouldn't really exist.
Event::listen('cms.router.beforeRoute', function () {
$host = request()->getHost();
$t = Translator::instance();
// default backend-defined locale stays as-is; we only tweak per domain
if (str_ends_with($host, 'maatkastenonline.nl') || str_ends_with($host, '127.0.0.1')) {
// force nl-NL to be the "nl" behind the scenes
if ($t->getLocale() === 'nl' || $t->getLocale() === null) {
$t->setLocale('nl-NL');
}
}
});
I assume the 'languages' need a new field or have to be able to be linked to each other somehow.
'name' = 'Nederlands (BE)
'code' = 'nl'
'hreflang' = 'nl-BE'
'name' = 'Nederlands (NL)
'code' = 'nl'
'hreflang' = 'nl-NL'
Then it can inject the code as always to display the right URL on the sitemap.
And then we can use the hreflang for the correct target audience?
I think the sitemap needs to output something like this...?
Note the .nl at the Dutch (Netherlands) which needs to be defined somewhere as well? Also on the language in case of Domain Driven Environment?
<url>
<loc>https://www.maatkastenonline.be/nl/</loc>
<!-- Dutch (Belgium) -->
<xhtml:link rel="alternate" hreflang="nl-BE" href="https://www.maatkastenonline.be/nl/" />
<!-- Dutch (Netherlands) -->
<xhtml:link rel="alternate" hreflang="nl-NL" href="https://www.maatkastenonline.nl/nl/" />
<!-- English -->
<xhtml:link rel="alternate" hreflang="en" href="https://www.maatkastenonline.be/en/" />
<!-- French -->
<xhtml:link rel="alternate" hreflang="fr" href="https://www.maatkastenonline.be/fr/" />
<!-- Default / fallback -->
<xhtml:link rel="alternate" hreflang="x-default" href="https://www.maatkastenonline.be/nl/" />
<lastmod>2025-11-05</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
https://discord.com/channels/816852513684193281/1434892348579381260
As an extension on wintercms/winter#1421, I would like to add a
new language nl.Plot twist, I already have
for mydomain.nl I want to use a new language
nl.since
nlalready exists, it should benl-NL.But we don't want the url
mydomain.nl/nl-NL. We wantmydomain.nl/nlto serve thenl-NLlanguage andmydomain.be/nlto serve the 'nl' language (or renamed to nl-BE).See this as if you want to serve different words for UK and USA (trousers <=> pants).
I tried this code, which seems to work at first glance but other problems arise on the
wn-sitemap-plugin(and maybe elsewhere).The nl-NL shows up on the sitemap, but the URL shouldn't really exist.
I assume the 'languages' need a new field or have to be able to be linked to each other somehow.
Then it can inject the code as always to display the right URL on the sitemap.
And then we can use the hreflang for the correct target audience?
I think the sitemap needs to output something like this...?
Note the
.nlat the Dutch (Netherlands) which needs to be defined somewhere as well? Also on the language in case ofDomain Driven Environment?https://discord.com/channels/816852513684193281/1434892348579381260