I need to send my server a list of localizations for a particular string.
Meaning, if my app has a string Foo which is localized as @"Foo" in English and @"Фу" in Russian, I'd like to send the server a list such as this:
What I think I need to be able to do is:
How do I do (1) and how do I do (2)?
Select your root project file, and then proceed to the project panel. Find the Localization section section, click the “plus” (+) icon, and add the desired languages. Select only the Localizable. strings file for localization.
Q: How does iOS determine the language for my app? A: To determine the language for your app, iOS considers not only the order of the user language preferences (in General > Language & Region of the Settings application) but also the localizations your app declares it supports.
A localized string can have different values depending on the language in which the project is being build. There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file.
“Base” Localization lproj” to your project. The purpose of this directory is to hold the default layouts of your views (i.e. storyboards/XIBs) in your “development language”. This was originally created to alleviate the previous practice of creating separate XIBs for each language (!).
You can retrieve all of the string keys by reading in English.lproj/Localizable.strings as a dictionary and fetching its keys:
NSString *stringsPath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:stringsPath];
To get each language's translation, you can iterate over the languages for each English key and use NSLocalizedStringFromTableInBundle
:
for (NSString *language in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) {
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]];
NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"Testing", @"Localizable", bundle, nil));
}
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