Sunday 5 February 2017

How to add language header to the Webview

In Android in the webviews, the urls are passed as a plain text . If you wan to send suppose language in the header then its pretty simple.

The language should be in the two alphabet format like en, sv, it  i.e.
en - English 
sv - Swedish 
it  - Italian 

"Accept-Language" is the keyword used to add the header in the webview 

This can be found out easily from the web from many available sites: 

the loadUrl(String url, Map<String, String> extraHeaders) method of the Webview allows to pass the language header.

This is the actual implementation :

Map<String, String> headers = new HashMap<>();
headers.put("Accept-Language",language));
mWebView.loadUrl(currentUrl,headers);

No comments:

Post a Comment

Localization implementation in android apps

The Language translation for the android apps to support the Localization. In android apps, if you want to support multiple languages ...