3

我有一个 UIWebView,我在其中显示了一个带有外语内容(在本例中为法语)的 HTML 文件,该文件由谷歌翻译。

英文原文是:

清除 - 用于停止所有计时器并清除视图最右侧显示的数量。

谷歌的翻译是这样的:

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

这是当法语是本地化语言时 iPhone 模拟器中显示的内容: 在 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]];

我查看了 Google、SO 和 UIWebView 以找到可以正确渲染的任何设置。使用的字体是 Verdana。

我该怎么做才能正确渲染?

4

2 回答 2

13

我找到了答案:见http://webdesign.about.com/od/localization/l/blhtmlcodes-fr.htm

这是您必须用于法语和其他单字符语言的元标记:

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

这适用于所有语言,包括双字符语言,如日语和中文。

于 2012-09-06T21:33:36.267 回答
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];
于 2012-09-06T20:57:51.120 回答