Change browser language
Asked Answered
A

3

7

I'm currently implementing a small web view in my application.

Everything is working fine with CefSharp but I have a small problem.

It seems like CefSharp is using something like en-US as the default browser language. I can't find any information about how to change the language that is used.

For my web view I need the browser to be set on a German language.

Is there any way to do that? Can the language be changed? If yes, how?

Accident answered 30/8, 2016 at 10:39 Comment(1)
Search for Locale in the project source, should be a property on CefSettings.Froze
B
10

You can change the language that:

CefSettings settingsBrowser = new CefSettings();
settingsBrowser.Locale = "de";

Cef.Initialize(settingsBrowser);
Bathypelagic answered 22/7, 2017 at 19:38 Comment(1)
Don't forget to include the locales/<locale>.pak into your application.Pierce
B
1

Try the following:

Implement IRequestHandler (example here) and implement OnBeforeResourceLoad this way:

// Other implementations here ...

CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
    var headers = request.Headers;
    headers.Add("Accept-Language", "de,de-DE");        
    return CefReturnValue.Continue;
}

Then set the RequestHandler of your browser instance with a new instance of this Implementation.

Brynhild answered 29/9, 2016 at 12:36 Comment(2)
You need to reassign headers after changing it as per the doco cefsharp.github.io/api/51.0.0/html/…Froze
Also that won't localise your app, change the locale to change the context menu etcFroze
T
1

via CefSettings you can change locale of the browser but you also need to change default language of "Accept-Language" header. The simplest way:

CefBrowserSettings browser_settings;
CefString(&browser_settings.accept_language_list) = L"de,de-DE";
Throaty answered 5/7, 2019 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.