在XCode中本地化HTML文件

tar*_*mes 3 iphone localization uiwebview ipad ios

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

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

/myapp
   /en.lrproj
       /Localizable.strings
   /fr.lrproj
       /Localizable.strings
   /webviews
      /view1
         /index.html
         /pic1.png
      /view2
         /index.html
         /pic2.png
Run Code Online (Sandbox Code Playgroud)

如您所见,我目前将视图组织到具有相关图像的自己的文件夹中.

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

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

显然,我不理解某些事情 - 我需要做些什么才能使这个工作?

谢谢,

蒂姆

Ola*_*laf 6

将index.html排列在Localized.strings旁边,将图片保存在Web视图目录中:

/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 
Run Code Online (Sandbox Code Playgroud)

构建文件路径:

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]];
Run Code Online (Sandbox Code Playgroud)

html树中的图片现在类似于

/myapp/en.lrproj/view1/index.html  
/myapp/webviews/view1/pic1.png
Run Code Online (Sandbox Code Playgroud)

在您的index.html内部使<img>标记指向../../../webview/pic1.png (不确定../您需要的数量.您可能想要打开终端,导航到/myapp/en.lrproj/view1/并使用ls ../../../webview/pic1.png.进行测试.)