Reading a string from a .strings file in Xcode

I am new to iOS, and I have a .strings file in which I store a failure expression that is viewed when I open my application.

However, it’s hard for me to figure out how to call the β€œdisclaimer” line from the disclaimer.strings file.

Help will be appreciated. Links to related pages are also welcome!

+6
source share
2 answers

Well, firstly, instead of using the .string file, if it has only a failure, then I just use the 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 make a localized version for each country, just add it to the "Localizable.strings" file. Your code is simple:

 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 to 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 the abandonment of this country.

+7
source

The naming convention for localization involves the Localizable.strings file, according to which you can provide different language versions.

The best way is to start by using operators in your code like this that returns localized content for disclaimer:

 NSLocalizedString(@"Disclaimer",@"Disclaimer") 

The next step is to call genstrings from the command line in the class directory:

 genstrings -o en.lproj *.m 
+2
source

Source: https://habr.com/ru/post/891491/


All Articles