iOS language settings

更新时间:
复制 MD 格式

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

  1. Add the Languages.bundle.zip file to your project to specify the supported languages.

  2. 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

  1. Add a multi-language bundle file.

    1. Add a strings file for each language that your app supports.

    2. Set the path for the multi-language files:

      [[APLanguageBundleLoader sharedLoader] setCustomLanguagesBundlePath:@""];
  2. 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".

  3. Set the text.

    Do not hardcode text that requires multi-language support. Use the __Text macro to load localized text:

     self.navigationItem.title = __TEXT(@"BeeCityPicker",@"BeeCityPicker:City Selection", @"City Selection");
    • @"BeeCityPicker": The name of the bundle that 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.