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.
The naming convention for Localizations expects a Localizable.strings file, under which you can then provide different language versions.
The best way is to start with using statements in your code like this one that returns the localized content for disclaimer :
NSLocalizedString(@"Disclaimer",@"Disclaimer")
The next step is to call genstrings from the command line on your classes directory:
genstrings -o en.lproj *.m
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With