NSLocalizedString “localizedStringForKey:value:table:”
- (NSString *)localizedStringForKey:(NSString *)key
value:(NSString *)value
table:(NSString *)tableName
文档将上述方法中的 tableName 参数描述为:要搜索的接收者的字符串表。如果 tableName 为 nil 或为空字符串,则该方法会尝试使用 Localized.strings 中的表...
我的问题是,如果我们创建一个它创建的 Localized.strings单独的字符串文件。我们的项目中没有创建表。桌子实际上在哪里?是否可以手动创建此类字符串表?我需要在我的项目中这样做...
我的最后一个问题是 - 我将什么值作为参数传递给 tableName 参数?
谢谢...
- (NSString *)localizedStringForKey:(NSString *)key
value:(NSString *)value
table:(NSString *)tableName
Doc says about the tableName argument in the above method as: The receiver’s string table to search. If tableName is nil or is an empty string, the method attempts to use the table in Localizable.strings...
My question is if we create a Localizable.strings it creates a string file alone. No tables are created in our project. Where is the table actually? Is it possible to create such string tables manually? I have a need to do that in my project...
And my final question is - What value I have pass as the argument to the tableName parameter?
Thank you...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,“表”指的是翻译文件。因此,对于 Localized.strings,您可以使用 NSLocalizedStringFromTable(@"foo", @"Localizable", @"comment") 从中获取翻译。然而,Localized.strings 是默认值,因此您通常只使用 NSLocalizedString(@"foo", @"comment")。如果添加新的翻译文件(例如,Settings.strings),则必须使用表名称来引用它。
In that context, "table" refers to the file of translations. So for Localizable.strings, you can get translations from it with NSLocalizedStringFromTable(@"foo", @"Localizable", @"comment"). Localizable.strings is the default, however, so you'd typically just use NSLocalizedString(@"foo", @"comment"). If you add a new translation file (say, Settings.strings), then you'd have use the table name to refer to it.
通过表 - 它仅意味着键值对。
有更多详细信息 文档
所以是的 - 你必须手动创建这些 - 因为你正在使用 NSBundle 辅助方法来处理本地化字符串 - 你可以使用
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
然后运行 genstrings
生成 .strings 文件和桌子。进行编辑以使这一点更清楚
字符串表只是键值对的列表。如果生成包含以下内容的 Localized.strings 文件:
现在您可以将此文件复制到另一个本地化的 .lproj 文件并将其更改为特定语言的值:
这就是表的全部含义。
By table - it just means a key-value pair.
There is more detail in the documentation
So yes - you have to create these manually - since you are using the NSBundle helper methods for localised strings - you can use
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
and then rungenstrings
to generate the .strings file and the tables.Edited to make this clearer
The Strings table is just a list of key value pairs. If you generate a Localizable.strings file that contains this:
Now you can copy this file to another localised .lproj file and change it to the values for the particular language:
That's all they mean by a table.