Multi lingual site get current culture code

Alexandru Dragut asked on November 3, 2017 11:19

I am working on a multilingual kentico website and it seems that neither of the ways of getting the current culture code works.

Things I'v tried:

LocalizationContext.PreferredCultureCode; DocumentContext.CurrentDocumentCulture.CultureCode; DocumentContext.CurrentDocument.DocumentCulture;

ALl of the expressions above return 'en-GB' even the url is http://localhost:8010/fr-FR/...

I ended up creating my own class for parsing the culture Code from the URL and set it to the LocalizationContext.PrefferedCultureCode but still, I encounter some errors on the translations.

Am I missing something ? Thanks !

Correct Answer

David te Kloese answered on November 3, 2017 12:02

I guess this is because you've not instructed Kentico which culture you're requesting. When doing MVC you have the Kentico app and your MVC app. You have to tell Kentico what you want, the CMS has no knowledge or your context if you don't instruct it to.

Check the Dancing Goat Kentico MVC sample-site on GitHub for examples on how to handle things like cultures: https://github.com/Kentico/Mvc

1 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on November 3, 2017 11:37

LocalizationContext.CurrentCulture.CultureCode should return the current culture code.

Preferred culture should be based on profile, the global site settings (default visitor culture) or previous choices (manually going to different culture).

When and how are you doing this code? Is it custom code in a Web Part... a Macro... in a custom task?

0 votesVote for this answer Mark as a Correct answer

Alexandru Dragut answered on November 3, 2017 11:46 (last edited on November 3, 2017 11:50)

I understand. Thanks for response.

I am doing this in a MVC Web application (with references to the Kentico CMS DLLs) and and debugging it into a Controller class.

The following LocalizationContext.CurrentCulture.CultureCode is still returning en-GB even the culture code in the URL is fr-FR

Also the following Property

DocumentContext.CurrentDocument.AbsoluteURL

is "http://websitename.com/en-GB/Home" even the URL in the browser is http://localhost:8001/fr-FR

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.