Issue with language select (thread culture does no...
# help-with-umbraco
b
Hi everyone, I've implemented a language selector that i've copied from another project that we have running in v13. After selecting the correct languages and binding a domain to a culture I can switch to the new link. As far as I can remember, that should be enough to change the UI culture in Umbraco. I'm being redirected to the correct url but the thread culture does not change. Meaning that the "active" field will always be true for the default language (NL) even though the language should switch after switching to the new Url. This is because
Copy code
Thread.CurrentThread.CurrentCulture.Name
will always be nl-NL Does anyone have a fix?
Copy code
var languages = _localizationService.GetAllLanguages();

        var publishedLanguages = languages.Where(x => pageCultures.Contains(x.IsoCode, StringComparer.InvariantCultureIgnoreCase));
        foreach (var lang in publishedLanguages)
        {
            var lowercaseIsoCode = lang.IsoCode.ToLower(System.Globalization.CultureInfo.CurrentCulture);
            if (!website.IsPublished(lowercaseIsoCode))
            {
                continue;
            }

            var isHomepage = current is HomePage;
            var content = !isHomepage && current.IsPublished(lowercaseIsoCode) ? current : website;

            var name = string.Empty;
            if (lang.CultureInfo!.IsNeutralCulture)
            {
                name = lang.CultureInfo.NativeName;
            }
            else
            {
                name = lang.CultureInfo.Parent.NativeName;
            }

            yield return new LanguageUrl
            {
                Name = name,
                IsoName = lang.CultureInfo?.TwoLetterISOLanguageName,
                Alt = GetLanguageUrlAlt(lang.CultureInfo!.TwoLetterISOLanguageName),
                Url = content.Url(lang.IsoCode),
                Active = lang.CultureInfo.Name.Equals(Thread.CurrentThread.CurrentCulture.Name, StringComparison.Ordinal)
            };
        }
j
Did you get anywhere with this? I have a similar problem
b
Issue appeared to be a weird bug, probably had to do with multilinguality. It worked on all other pages so after deleting the homepage and creating a new one it suddenly worked
k
What version of Umbraco are you running? You state you've copied it from a v13, to another v13 and if so, which minor? I'm asking because there has been interesting bugs with culture after they introduced the eager routing policy. That being said, you aren't using CurrentUICulture in the code above, but CurrentCulture, - is CurrentUICulture also the "wrong" language ?
b
Yes they were both the same (wrong) language. We've copied the code from a 13.2.0 to a 13.4.0 site.
9 Views