从文件路径加载笔尖
我们可能需要使用
[NSBundle -pathForResource:ofType:inDirectory:forLocalization:]
我认为这是可能的结果来加载笔尖,但我能找到的所有方法只需要名称而不需要引导路径信息。
我们正在探索一种通过一个代码库同时提供 fr-Fr 和 fr-CA 的方法。我们的客户想要 fr-CA 翻译,我们担心可能会有另一个客户想要 fr-Fr 翻译。我想我们可以根据所选语言找到正确的笔尖。
谢谢
We might have a need for loading a nib using the results of
[NSBundle -pathForResource:ofType:inDirectory:forLocalization:]
I thought this would be possible, but all the methods I can find only want the name not leading path info.
We are exploring a way to provide both fr-Fr and fr-CA through one code base. Our client wants a fr-CA translation and we're afraid we might have another customer that wants a fr-Fr translation. I was thinking we could path to correct nib based on the selected language.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
路径查找考虑了用户的区域设置首选项。如果您提供正确的本地化目录 (
.lproj
),系统应该加载正确的笔尖。根据 Apple 文档:
不幸的是,苹果的文档是自相矛盾且不完整的。如果您查看“国际化和编程主题”的“语言和区域设置指定”部分,您将在“语言和区域设置 ID”下找到这个宝石:
这并不完全正确。如果您查看 Apple 自己的应用程序,您会发现 iOS 确实支持某些区域指定,但仅限于 Apple 关心的区域。例如,请参阅最近的 Mobile Safari 中的 .lproj 目录列表:
请注意,支持两个中文区域、一个英式英语区域和一个葡萄牙葡萄牙语区域。但这些都没有解决
fr_CA
与fr_FR
的问题。为此,让我们再次看看 MobileSafari。它必须实现自己的智能查找,因为它有大量更精细区分的
StaticBookmarks-xx_YY.plist
文件。所以,这就是解决方案:使用仍然可用的区域设置函数,并相应地进行自己的查找。
The path lookup takes into account the user's locale preferences. If you provide the proper localization directories (
.lproj
), the right nib should be loaded by the system.Per Apple's documentation:
Unfortunately, Apple's documentation is self-contradictory and incomplete. If you look at "Internationalization and Programming Topics", section "Language and Locale Designations", you will find under "Language and Locale IDs" this gem:
This is not entirely true. If you look at Apple's own applications, you will see that iOS does support some region designations, but only the ones Apple cares about. See for example the list of .lproj directories in a recent Mobile Safari:
Notice that two Chinese regions, a British English region, and a Portugal Portuguese region are supported. But none of these solves the problem of
fr_CA
versusfr_FR
.For that, let's look at MobileSafari again. It must implement its own smart lookup, because it has plenty of more finely distinguished
StaticBookmarks-xx_YY.plist
files.So, that's the solution: Use the locale functions that are still available, and do your own lookup accordingly.
我不明白这个问题。
您可以完美地拥有两个不同的 NIB,分别用于法国和加拿大(法语),因为 Xcode 支持它。
只需为您的文件添加新的本地化:
然后使用视图控制器加载 NIB,
initWithNibName
方法。根据设备语言设置,将使用正确的语言。I don't understand the problem.
You can perfectly have two different NIBs, for France and Canada (french), as it's supported by Xcode.
Simply add new localization for your file(s):
Then use a view controller to load the NIB, with the
initWithNibName
method. The correct one will be used, depending on the device language settings.