2012-09-06 74 views
1

我有一個UIWebView,其中顯示帶有由Google翻譯的外語內容(本例爲法語)的HTML文件。iOS UIWebView無法正確渲染外語

英文原文是:

清除 - 用於停止所有計時器並清除顯示視圖的遠 正確的金額。

從谷歌翻譯是這樣的:

修護 - 柏美D'arrêter所有領域萊minuteries等修護萊 montantsindiquésA L'極端共和區德拉VUE。

這是什麼顯示在iPhone模擬器時,法國是本地化語言: rendering of French translation in UIWebView

這是我使用加載它的代碼:我在谷歌看上去

// 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]]; 

,SO和UIWebView找到可以正確渲染的任何設置。正在使用的字體是Verdana。

我需要做些什麼才能正確渲染?

+0

你是如何加載HTML的?它可能與某些編碼問題有關 – Ismael

+0

請參閱上面編輯的問題,其中顯示加載HTML文件的代碼。 – SpokaneDude

回答

0

嘗試加載你的HTML轉換成字符串(你必須知道你的文件的編碼)

NSString *indexPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"instRST-%@", sysLangCode] ofType:@"html"]; 
// use correct encoding 
NSString *content = [NSString stringWithContentsOfFile:indexPath encoding:NSUTF8StringEncoding error:nil]; 
[webView loadHTMLString:content baseURL:nil]; 
+0

如果我使用獨立瀏覽器(Firefox,Safari或Chrome),則它們都無法正確渲染。這有幫助嗎? – SpokaneDude