How to set the default language in iOS

Source: Internet
Author: User

In iOS development, we need to perform localization to display the content of some resources (mainly strings) in different languages. For example, "edit" is displayed in English, and "Edit" is displayed in Chinese ". The customer of a recent project requested to support two languages: English and Italian, with emphasis on the default Italian language. The current language is not English and Italian is required to display Italian. The Localization native development region option in xcode is used to set the default region. In this way, the localized resources are displayed in the localized region, and the default resources are displayed in the non-localized region. However, this setting does not mean this. The default string uses English. No matter what the development region is set, the non-localized area displays English. In order to implement the function of this default language, I can only try other ways. Finally, I implemented it using code. The basic idea is to find that the current language is not supported by the system in English and Italian, unified Access to the specified resource file and the default resource is returned. The Code is as follows: # define CURR_LANG ([NSLocale preferredLanguages] objectAtIndex: 0]) + (NSString *) DPLocalizedString :( NSString *) translation_key {NSString * s = NSLocalizedString (translation_key, nil); if (! [CURR_LANG isEqual: @ "en"] &! [CURR_LANG isEqual: @ "it"]) {NSString * path = [[NSBundle mainBundle] pathForResource: @ "it" ofType: @ "lproj"]; NSBundle * export agebundle = [NSBundle bundleWithPath: path]; s = [Export agebundle localizedStringForKey: translation_key value: @ "" table: nil];} return s, in the code, you can change the NSLocalizedString macro to DPLocalizdString to change the default language.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.