An iPhone using a language other than the one installed on the OS / device?

Is it possible that my application runs in a different language than the one installed in the OS? I want to have a language switch in the settings menu of my applications, where the user can, for example, select german for the application, and his system works in English.

From what I have already read, it seems that this is impossible without my own localization mechanism ...

What do you think?

Cheerz pawi

+3
source share
2 answers

To do this, you need to implement your custom resource loading mechanism. For example, you can no longer use the macro NSLocalizedString or [NSBundle pathForResource:]. You always need to specify paths, including localization (as in the de.lproj / MyStrings.strings file, and not just in MyStrings.strings). I would suggest against this, if absolutely necessary.

-1
source

this can be done easily, although it took me weeks to figure out how :-)

I have an iPhone app called iDEX, which is Romanian. On the iPad, Romanian is not available as the user interface language, so I wanted to give the user the opportunity to choose Romanian in the application settings, since the device settings do not include it.

What you need to do is internationalize the application and localize it as usual. Then in the main method , set the AppleLanguages key of the standard NSUserDefaults to the language and country of your choice, for example

 int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[NSArray arrayWithObject:@"ro_RO"] forKey:@"AppleLanguages"]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool drain]; return retVal; } 

UIApplicationMain() , because it is at this point that the UIKit infrastructure is loaded and is determined by language by default.

It is also important to specify both the language and the country (for example, @ "ro_RO", and not just @ "ro"), otherwise your application may crash when you install the key.

That way, all NSBundle calls that support localization will look for the language you programmed, not the one that is installed on the device.

Hope this helps ...

+10
source

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


All Articles