Sitemap culture issue
# help-with-umbraco
c
Umb V10.6.1 site in 3 languages including ar-ae (Arabic). I have a sitemap based on the one in the docs. The priority value is coming out as 0,5 for the ar-ae one, but as 0.5 for en-gb & ar-en. I'm being told that Google is complaining about the comma decimal designator. However, when I run it through an xmlsite map checker it passes. I've tried outputting the value as InvariantCulture, and when debugging, it shows it as 0.5, but when I run the page in a browser, it still shows 0,5. Here is the code I've tried so far:-
Copy code
void RenderSiteMapUrlEntry(IPublishedContent node)
    {
        var changeFreq = node.Value("searchEngineChangeFrequency", fallback: Fallback.To(Fallback.Ancestors, Fallback.DefaultValue), defaultValue: "monthly");
        // with the relative priority, this is a per page setting only, so we're not using recursion, so we won't set Fallback.ToAncestors here and we'll default to 0.5 if no value is set
        decimal priority = 0.5m;
        
        if (node.HasValue("searchEngineRelativePriority")) {
            string priorityConverted = node.Value<decimal>("searchEngineRelativePriority").ToString(CultureInfo.InvariantCulture);
            priority = decimal.Parse(priorityConverted, CultureInfo.InvariantCulture);
        }

        <url>
            <loc>@node.Url(mode: UrlMode.Absolute)</loc>
            <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod>
            <changefreq>@changeFreq</changefreq>
            <priority>@priority</priority>  // Shows 0.5 here but 0,5 in the browser!
        </url>
    }
I have changed the fallback priority to something other than 0.5 and it all remains as it should, so I know the "if" statement is working. I also tried setting the priority not to vary by culture in the docType composition, but it still changes with language. I think it should vary by language anyway so that editors can set it appropriately for the market. Does anyone have any suggestions? Thanks.
m
So priority is a decimal, and you're just calling
Copy code
@priority
which means that it will do the default ToString that is configured on the decimal. Have you tried using
Copy code
@priority.ToString("F",CultureInfo.InvariantCulture)
?
c
Not quite, I'm doing much more than that:-
Copy code
if (node.HasValue("searchEngineRelativePriority")) {
            string priorityConverted = node.Value<decimal>("searchEngineRelativePriority").ToString(CultureInfo.InvariantCulture);
            **priority** = decimal.Parse(priorityConverted, CultureInfo.InvariantCulture);
        }
I'll try yours though 😉
m
You're parsing it as invariant and then you're displaying it as a string which will format it using the culture that is set in the request
c
It all depends on what explanations and examples you land on when searching. Obviously mine were way off. Yours worked. Thanks. 🙂
5 Views