how can i translate contents from front end on changing the culture?

Muhammad Kaleem asked on May 21, 2019 19:31

i have enable some custom cultures in cms, when i change culture from cms then translated contents showing in frontend, but when i change the culture of cms to english and after refreshing my web page i'm changing my page url from "abc.com" to "abc.com/ar-KW" in this situation why me contents not translating to arabic, please suggest

thanks

Recent Answers


David te Kloese answered on May 23, 2019 09:59

Hi,

in the sites application can you check what is set as default content culture and default visitor culture?

https://content.screencast.com/users/DavidTK/folders/Jing/media/37ffe0e9-7321-4411-a41d-d7079bbe5c46/2019-05-23_0955.png

Secondly if I understand correctly when changing the URL you don't get content from that specific culture?

You tagged it MVC, so how is your route setup? Do you use the first part as a culture in your code?

And when you get the specific page using your provider do you pass on that culture property to retrieve the content?

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 11:11

thanks David, yes i have pass culture property and my url is also fine i.e

abc.com/en-Us/news abc.com/ar-KW/news

my contents should be translated into arabic when i move to thsi url "abc.com/ar-KW/news" but this is not happening

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on May 23, 2019 11:26

how is your route setup? Do you use the first part as a culture in your code?

Do you have any SiteCultureConstraint in your routing in place to verify it's also available on current site?

And when you get the specific page using your provider do you pass on that culture property to retrieve the content?

Check out the Documentation for examples on how to set it up: docs.kentico.com/k12/.../setting-up-multilingual-mvc-projects

Make sure you have something like this in place:

    // Assigns a custom route handler to the route
    route.RouteHandler = new MultiCultureMvcRouteHandler();
0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 11:32

yes my route implementation is same,

var home = HomeProvider.GetHome("/home", LocalizationContext.CurrentCulture.CultureCode, SiteContext.CurrentSiteName);

i'm retrieving data by this query, should i modify this or while getting data should i get localized data?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on May 23, 2019 11:36

Just to confirm I'd say log or output that LocalizationContext.CurrentCulture.CultureCode somewhere so you are sure it got the culture you expect.

What information are you expecting to be translated? page fields or something else?

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 11:39

LocalizationContext.CurrentCulture.CultureCode

this returns the current culturcode, i want to translate page fields

thanks

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on May 23, 2019 11:42

but is it actually ar-KW or does it come back as en-US? Because if the current context is still set to English you'll never get other content.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 11:50

my default culture is en-US and when i move to ar-KW then contents showing same as en-US

also when i change culture from cms then contents translation work but from front-end it does not work

for example in cms i select ar-KW then my contents showing in arabic weather i move with ar-Kw or en-US

0 votesVote for this answer Mark as a Correct answer

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