Configure language settings for your iOS application during mPaaS integration, including defaulting to the system language, switching languages at runtime, and adding multi-language text support.
mPaaS provides a multi-language framework that lets you set and switch the display language for your iOS application.
Default to the system language
-
Add the Languages.bundle.zip file to your project to specify the supported languages.
-
After the application starts, initialize the multi-language framework:
//#import <mPaas/APLanguage.h> [APLanguageSetting sharedSetting];
Get the current app language
Use the following code to retrieve the current app language:
NSString *currentLanguage = [APLanguageSetting currentLanguage].name;
Change the current app language
Check the Languages.bundle file in your project for supported languages. To change the current app language, use the following code:
[APLanguageSetting setCurrentLanguageWithName:@"en"];
Support multiple languages for text
-
Add a multi-language bundle file.
-
Add a strings file for each language that your app supports.
-
Set the path for the multi-language files:
[[APLanguageBundleLoader sharedLoader] setCustomLanguagesBundlePath:@""];
-
-
Implement the strings files.
When creating strings files, follow these guidelines:
-
Each text entry in a strings file uses the following format: The key is on the left side of the equal sign, and the display text for the corresponding language is on the right.
"BeeCityPicker : City Selection"="City Selection" -
The key for a specific text entry must be the same in all strings files. Define the key by combining the bundle name and the text content, such as
"BeeCityPicker: City Selection".
-
-
Set the text.
Do not hardcode text that requires multi-language support. Use the
__Textmacro to load localized text:self.navigationItem.title = __TEXT(@"BeeCityPicker",@"BeeCityPicker:City Selection", @"City Selection");-
@"BeeCityPicker": The name of thebundlethat contains the string table. This is typically the name of the module resource bundle. -
@"BeeCityPicker : City Selection": The key for the text in the string table. -
@"City Selection": The default text to display if the key is not found in the string table.
-