strings文件读取字符串

strings文件读取字符串

本文介绍了从XCode中的.strings文件读取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS新手,我有一个.strings文件,其中存储了我的应用程序打开时查看的免责声明。



但是,我有麻烦弄清楚如何从disclaimer.strings文件中调用免责声明字符串。



帮助将不胜感激。此外,赞赏相关页面的链接!

解决方案

嗯,首先,如果只有使用.string文件,而不是使用.string文件免责声明,然后我只使用一个txt文件:

  NSString * fName = [[NSBundle mainBundle] pathForResource:@免责声明ofType:@txt]; 
if(fName){
self.disclaimer = [NSString stringWithContentsOfFile:fName];
}

另一方面,如果你想为每个国家做本地化版本,然后将其添加到Localizable.strings文件中。您的代码只是:

  self.disclaimer = NSLocalizedString(@disclaimer,@每个国家/地区的免责声明); 

然后使用genstrings收集所有可本地化的字符串,或创建Localizable.strings(File \\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ c>disclaimer=这是我们免责声明的英文版......;

然后您创建一个新的语言版本的Localizable.strings并使用该国家/地区的免责声明进行编辑。


I am new to iOS and I have a .strings file in which I store a disclaimer that is viewed when my application is opened.

However, I am having trouble figuring out how to call the "disclaimer" string from the disclaimer.strings file.

Help would be appreciated. Also, links to relevant pages are appreciated!

解决方案

Well, first, rather than using a .string file, if there's only the disclaimer in it, then I would just use a txt file:

NSString * fName = [[NSBundle mainBundle] pathForResource:@"disclaimer" ofType:@"txt"];
if (fName) {
    self.disclaimer = [NSString stringWithContentsOfFile: fName];
}

On the other hand, if you want to do a localized version for each country, then just add it to your "Localizable.strings" file. Your code is just:

self.disclaimer = NSLocalizedString(@"disclaimer", @"Disclaimer text for each country");

Then either use genstrings to collect all your Localizable strings, or create "Localizable.strings" (File\New\New File\ioS\Resource\Strings File), and then you can edit/add in the text:

"disclaimer" = "This is the English version of our disclaimer...";

Then you create a new language version of Localizable.strings and edit it with that country's disclaimer.

这篇关于从XCode中的.strings文件读取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 12:07