将.string文件作为NSDictionary打开 [英] Open .string files as an NSDictionary

查看:65
本文介绍了将.string文件作为NSDictionary打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将.string文件作为NSDictionary打开?

How do I open a .string file as an NSDictionary?

编辑:我希望能够像这样使用它:

I want to be able to use it like this:



NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"dict.plist"];
NSDictionary *strings = [[NSDictionary alloc] initWithContentsOfFile:@"Strings.strings"];


推荐答案

如果您确实希望在字典中使用它,则可以使用[NSDictionary dictionaryWithContentsOfFile:]加载它,因为它位于格式.我以前在Mac OS X上使用过此技术,但不确定是否可以在iOS上执行相同的操作.

If you really want it in a dictionary, you can load it using [NSDictionary dictionaryWithContentsOfFile:], since it is in “Old-style ASCII” format. I have used this technique before on Mac OS X, but I'm not sure you can do the same for iOS.

但是,如果要翻译特定的字符串,至少有两种方法可以实现:

However, if you want a translation for a particular string, there are at least two ways to do it:

  1. NSLocalizedStringFromTable() will allow you to load strings from files other than the normal Localizable.strings file. Provide the name of your strings file (without the extension).

NSBundle的 localizedStringForKey:value:table: 方法.这基本上执行与上述方法相同的操作,并且如上所述,提供不带扩展名的字符串文件的名称.

NSBundle's localizedStringForKey:value:table: method. This essentially performs the same operations as the method above, and as above, provide the name of your strings file without the extension.

这篇关于将.string文件作为NSDictionary打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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