Automatically Detect Language does not work

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
"Automatically Detect Language" was checked but does not work for me.

For example, my website has English(first/default) and Chinese, if client browser language set as Chinese the website opened still directing to the first language English but Chinese is expected.

Please Help.
5 years ago
Hello

Default nopCommerce not supported detect language automatically.

You have to do your custom code for same

You can review this post and this post

We've already done this requirement for our client you can PM me if you want demo.

Thanks,
Jatin
5 years ago
forefront wrote:
Hello

Default nopCommerce not supported detect language automatically.

You have to do your custom code for same

You can review this post and this post

We've already done this requirement for our client you can PM me if you want demo.

Thanks,
Jatin


Many thanks for your reply. I'll have a look.
5 years ago
Hi,

I am having same kind of situation with my site. My site using EN and IT languages. Whenever I visited my site from outside Italy, I'm still viewing site in Italian first. I'm using nopCommerce version 4.10
I resolved this issue using this link https://stackoverflow.com/a/54877321

Here is modification to do

Under method GetLanguageFromRequest() replace this lines of code
var requestCulture = _httpContextAccessor.HttpContext.Features.Get<IRequestCultureFeature>()?.RequestCulture;


with this below lines
 
var requestCulture = _httpContextAccessor.HttpContext.Request.GetTypedHeaders()
                       .AcceptLanguage
                       .OrderByDescending(x => x.Quality ?? 1) // Quality defines priority from 0 to 1, where 1 is the highest.
                       .Select(x => x.Value.ToString())
                       .FirstOrDefault();
4 years ago
Hi, if i try the change above i have error in this line

   //try to get language by culture name
            var requestLanguage = _languageService.GetAllLanguages().FirstOrDefault(language =>
                language.LanguageCulture.Equals(requestCulture.Culture.Name, StringComparison.InvariantCultureIgnoreCase));

string not contain a definition of Culture.

How can i fix this issue?
4 years ago
That select is taking the value.

Change it to this:

//try to get language by culture name
            var requestLanguage = _languageService.GetAllLanguages().FirstOrDefault(language =>
                language.LanguageCulture.Equals(requestCulture, StringComparison.InvariantCultureIgnoreCase));
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.