Search code examples
kentico

Kentico ResHelper.GetString returning wrong translation


My Kentico 11 site's Default content culture and Visitor culture are both set to German. When I check under the settings tabs for the pages, I can see that their culture is also set to German. When I put a breakpoint in the debugger and check the value of LocalizationContext.CurrentCulture it also returns German.

I also have the following set in web.config:

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="de-DE" uiCulture="en-US" />

However, ResHelper.GetString only returns the english translation.

I'm guessing it's because somehow in localization module, english is still the default language: enter image description here

If this is the issue how can I change this?

Update: I thought it might be related to this issue but Thread.CurrentThread.CurrentCulture is also returning de-De

Another Update:

ResHelper.GetString("Key", CMS.Localization.LocalizationContext.CurrentCulture.CultureCode); returns the German translation

Really good update:

Thanks to Brenden Kehren I've narrowed it down. When I call the function in a webpart like so there is no issue:

<%# CMS.Helpers.ResHelper.GetString("key") %>

But when I call it in a webservice this is where the issue comes from!


Solution

  • It's returning English text because you have English text in the German field. Your settings sound correct, appears to be a data entry issue based on your screenshot.

    UPDATE
    Based on the new screenshot and updated question, are you testing your visitor site in a new in-private window? If you have the culture in the Pages app set to English for editing and view the site in the same browser/new tab, it will show English. If you change the language in that browser on the live site, it will also update the CMS the next time it gets a full page refresh. So always test in a private browser window to eliminate the possibilities of caching or old cookies.

    UPDATE 2
    For this to work properly you need to access the web service in the context of a user. Meaning if a user is on the site and loads a page, the system will know what culture the user is in. Whereas if you're using it in a scheduled task, that does not run in the context of a user navigating the site, so you'd need to specify the culture in which to get the value for.