﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33998	Use alternates and i18n generate duplicated URLs in the sitemap	brenosss	nobody	"If the i18n variable is set for True, the SiteMapClass generates a different URL for each item in LANGUAGES, but I'm using the alternates I expected to have only one URL for the default language and have the translations version in the alternates URLs.

The current function:

{{{
    def _items(self):
        if self.i18n:
            # Create (item, lang_code) tuples for all items and languages.
            # This is necessary to paginate with all languages already considered.
            items = [
                (item, lang_code)
                for lang_code in self._languages()
                for item in self.items()
            ]
            return items
        return self.items()
}}}

This is a e.g of a result:

{{{
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"" xmlns:xhtml=""http://www.w3.org/1999/xhtml"">
    <url>
        <loc>https://example.com/en/contact</loc>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel=""alternate"" hreflang=""en"" href=""https://example.com/en/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""es"" href=""https://example.com/es/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""el"" href=""https://example.com/el/contact"" />
    </url>
    <url>
        <loc>https://example.com/es/contact</loc>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel=""alternate"" hreflang=""en"" href=""https://example.com/en/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""es"" href=""https://example.com/es/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""el"" href=""https://example.com/el/contact"" />
    </url>
    <url>
        <loc>https://example.com/el/contact</loc>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel=""alternate"" hreflang=""en"" href=""https://example.com/en/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""es"" href=""https://example.com/es/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""el"" href=""https://example.com/el/contact"" />
    </url>
</urlset>
}}}

I propose to verify if the alternates is True and generate the items only for the default language:

{{{
    def _items(self):
        if self.i18n:
            if self.alternates:
                lang_code = self.default_lang or settings.LANGUAGE_CODE
                items = self.items()
                items = [
                    # The url will be generated based on the default language the translations links will be added in the alternate links
                    (item, lang_code)
                    for item in items
                ]
                return items
            # Create (item, lang_code) tuples for all items and languages.
            # This is necessary to paginate with all languages already considered.
            items = [
                (item, lang_code)
                for lang_code in self._languages()
                for item in self.items()
            ]
            return items
        return self.items()
}}}

Then i expected a result more like:
{{{
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"" xmlns:xhtml=""http://www.w3.org/1999/xhtml"">
    <url>
        <loc>https://example.com/en/contact</loc>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <xhtml:link rel=""alternate"" hreflang=""en"" href=""https://example.com/en/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""es"" href=""https://example.com/es/contact"" />
        <xhtml:link rel=""alternate"" hreflang=""el"" href=""https://example.com/el/contact"" />
    </url>
</urlset>
}}}

This makes sense? can I start work on it?"	Bug	new	contrib.sitemaps	4.0	Normal		sitemap, i18n, alternates		Unreviewed	0	0	0	0	0	0
