Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIWebView not rendering foreign languages correctly

Tags:

ios

uiwebview

I have a UIWebView in which I display a HTML file with foreign language content (in this case French), which was translated by Google.

The original English text is:

Clear - used to stop all timers and clear the amounts shown to the far right of the view.

The translation from Google is this:

Effacer - permet d'arrêter toutes les minuteries et effacer les montants indiqués à l'extrême droite de la vue.

This is what's displayed in the iPhone Simulator when French is the localized language: rendering of French translation in UIWebView

This is the code I am using to load it:

//  determine what the language for this locale is...
NSString *sysLangCode = [[NSLocale preferredLanguages] objectAtIndex:0];

//  contatenate the language code to the filename
NSURL *indexURL = [[NSBundle mainBundle] URLForResource: [NSString stringWithFormat:@"instRST-%@", sysLangCode]
                withExtension:@"html"];

//  load it...
[webView loadRequest:[NSURLRequest requestWithURL:indexURL]];

I have looked in Google, SO and UIWebView to find any settings that would make this render correctly. The font being used is Verdana.

What do I have to do to get this to render correctly?

like image 266
SpokaneDude Avatar asked Aug 07 '26 12:08

SpokaneDude


1 Answers

I found the answer: see http://webdesign.about.com/od/localization/l/blhtmlcodes-fr.htm

This is the meta tag you have to use for French and other one-character languages:

<meta http-equiv="content-type" content="text/html;charset=utf-8">

This works for all languages, including two-character languages, like Japanese and Chinese.

like image 121
SpokaneDude Avatar answered Aug 09 '26 00:08

SpokaneDude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!