一个 iOS 应用程序中的多个 Localizable.strings 文件 [英] Multiple Localizable.strings files in one iOS app

查看:25
本文介绍了一个 iOS 应用程序中的多个 Localizable.strings 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在一个应用中拥有多个具有不同本地化的组件?

Is it possible to have multiple components that have their separate localizations in an app?

例如,我想在我的应用程序中本地化字符串,但也使用本地化的 ShareKit(因此我的包将包含 2 个位于不同位置的 Localizable.strings).因此,ShareKit 包含 en.lproj 和 de.lproj 之类的文件夹,其中包含 Localizable.strings 文件,我想为我的项目的其余部分创建相同的文件夹,但将它们分开.

For example I want to localize strings in my app but also use ShareKit which is localized itself (so my bundle will contain 2 Localizable.strings in different locations). So, ShareKit contains folders like en.lproj and de.lproj that contain Localizable.strings files and I want to create the same for the rest of my project but keep them separate.

我尝试将它们分开,这导致我的应用程序的字符串未被使用.有什么想法吗?

I have tried just keeping them separate and that resulted in the strings of my app not being used. Any ideas?

推荐答案

有一种方法很简单.

有几个用于本地化的宏,其中之一是 NSLocalizedStringFromTable().这需要三个参数:

There are several macros for localizing, one of which is NSLocalizedStringFromTable(). This takes three parameters:

  1. 要本地化的字符串
  2. 表名,就是一个文件名
  3. 注释,就像 NSLocalizedString()

如果你使用表名,那么你可以有另一个字符串文件,即如果我这样做 NSLocalizedStringFromTable(@"name", @"MyStrings", @"whatever"); 然后把我的字符串在 MyStrings.strings 中它将使用它.

If you use a table name then you can have another strings file, i.e. if I do NSLocalizedStringFromTable(@"name", @"MyStrings", @"whatever"); then put my strings in MyStrings.strings it will use that.

参见 Matt Gallagher 的 post 关于这个.

See Matt Gallagher's post about this.

这篇关于一个 iOS 应用程序中的多个 Localizable.strings 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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