- 🇨🇭Switzerland handkerchief
+1, similar case with me.
Default language is English.
Second language is German.But the Site uses only German without prefixes and so on. Reason for that setting are problems with module translations if you don't install drupal with english as default languge.
So aliases only exist in German, but the sitemap will always create the English-Version wich is node/1, node/2 etc.
- 🇨🇭Switzerland handkerchief
Workaround:
/** * Implements hook_simple_sitemap_links_alter(). */ function HOOK_simple_sitemap_links_alter(array &$links, $sitemap_variant) { $sitemap_id = $sitemap_variant->id(); $node_storage = \Drupal::entityTypeManager()->getStorage('node'); if ($sitemap_id === 'default') { foreach ($links as $key => $link) { $nid = $link['meta']['entity_info']['id']; $node = $node_storage->load($nid); if (str_contains($link['url'], '/node/')) { $links[$key]['url'] = $node->toUrl()->setAbsolute()->toString(); } } } }
- 🇳🇱Netherlands Dimiter
I think I am experiencing a very similar issue, except that I don't have any problems with nodes but with pages from views that should be added to the sitemap. The individual nodes are all correctly added to the sitemap (only the non-english version, using the correct canonical url), but the pages from a view that has been added to the sitemap (using "Simple XML Sitemap (Views)") are included both in the English and non-english language, even tough the view and all the nodes in the view are all configured to use the non-english language.
- 🇷🇺Russia walkingdexter
I tested the following scenario on a clean install with
4.x-dev
:- Enable two languages - English and non-english.
- Set English as default language.
- Use the "Selected language" plugin for language detection and configure it with a non-english language.
- Enable content translation for the "Article" content type.
- Add a new node of type "Article" and translate it into a non-english language.
Now when I set a URL alias for the created node, I get a 404 error if the alias has a non-english language. If I change the alias language to English or unspecified, then the 404 error does not occur. The sitemap is also correct in this case.
So I can't reproduce the problem on a clean install. Maybe I'm missing something. Feel free to reopen if you can provide more information to reproduce the problem. In other cases see #4 and #5 for possible solutions. Also consider changing the URL alias language.
- 🇨🇭Switzerland handkerchief
@walkingdexter You tested another scenario, our scenario is:
- New Drupal installation in English
- Add another language, e.g. German. But English still is the default language.
- Add nodes directly in the German language, no translations
- Generate the sitemap
Then you will get the effects described in #3.
I thinks the problem is, the site default language is English, but only nodes in German exist without translations. Again the reason for this site configuration are effects like 🐛 Configuration language being overwritten during module install Needs work or 🐛 Installing a module causes translations to be overwritten Fixed . So to avoid such translation problems if you have another default or installation language as English, we use English as default language, although only German is used without translations.
- 🇷🇺Russia walkingdexter
@handkerchief In your scenario I still get the 404 error. Can you provide more details on step 3?
- Is the Content Translation module disabled?
- What settings are set on /admin/config/regional/content-language?
- What settings are set on /admin/config/regional/language/detection?