在XCode中本地化HTML文件 [英] Localizing HTML files in XCode

查看:364
本文介绍了在XCode中本地化HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地化的iOS应用程序,我希望在其中包含一些本地化的HTML文件。我无法理解如何做到这一点。

I have a localized iOS application in which I wish to include some localized HTML files. I can't work out how to do it.

目前,我的文件夹结构如下所示:

Currently, my folder structure looks like this:

/myapp
   /en.lrproj
       /Localizable.strings
   /fr.lrproj
       /Localizable.strings
   /webviews
      /view1
         /index.html
         /pic1.png
      /view2
         /index.html
         /pic2.png

如您所见,我目前将视图组织到他们自己的文件夹中并附带相关图像。

As you can see, I currently have the views organized into their own folders with the associated images.

在XCode中,当我选择Localizable.strings文件时,我可以添加新的本地化。在搜索此问题的解决方案时,我看到其他人对HTML文件也做了同样的事情,但是当我选择HTML文件时没有显示本地化的选项,所以我想知道文件夹结构是否是问题。

In XCode, when I selected the Localizable.strings files I can add new localizations. When searching for the solution to this problem I see that other people have done the same for the HTML files, however when I select the HTML files there are no options displayed for localizations, so I'm wondering if the folder structure is the problem.

另一方面,我不知道如何将HTML结构化为语言代码文件夹,而不是复制必须同时存在的图形。

On the other hand, I don't know how to structure the HTML into language code folders whilst not replicating the graphics that have to be along side.

显然我不明白 - 我需要做些什么来实现这个目标?

Clearly I'm not understanding something - what do I need to do to get this working?

谢谢,

Tim

推荐答案

将index.html安排在Localized.strings旁边,将图片保存在网页浏览目录中:

Arrange your index.html right next to the Localized.strings, keep the pics in the web views directory:

/myapp
   /en.lrproj
       /Localizable.strings
       /view1/index.html
       /view2/index.html
   /fr.lrproj
       /Localizable.strings
       /view1/index.html
       /view2/index.html
   /webviews
      /view1
         /pic1.png
      /view2
         /index.html
         /pic2.png 

构建文件路径:

NSArray* availableLocalizations = [[NSBundle mainBundle] localizations];    
NSArray* userPrefered = [NSBundle preferredLocalizationsFromArray:availableLocalizations forPreferences:[NSLocale preferredLanguages]];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"view" forLocalization:[userPrefered objectAtIndex:0]];

html树中的图片现在类似于

The picture in the html tree are now similar to

/myapp/en.lrproj/view1/index.html  
/myapp/webviews/view1/pic1.png

在index.html中,使< img> 标记指向 ../../../ webview / pic1.png
(不确定 ../ '的数量你需要的。你可能想打开一个终端,导航到/myapp/en.lrproj/view1/并用 ls ../../../webview/pic1.png 。)

Inside your index.html make the <img> tags point to ../../../webview/pic1.png (Not sure about the number of ../'s that you need. You might want to open a terminal, navigate to /myapp/en.lrproj/view1/ and test with ls ../../../webview/pic1.png. )

这篇关于在XCode中本地化HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆