[Swift 3.0] iOS International switch language, swiftios

Source: Internet
Author: User

[Swift 3.0] iOS International switch language, swiftios

 

 

Some apps may have the option to switch the language. The simplest way is to combine the system's automatic switch:

Fileprivate var localizedBundle: Bundle = {return Bundle (path: Bundle. main. path (forResource: "zh-Hans", ofType: "lproj ")!)!} () Public func LocalizedString (_ key: String, comment: String)-> String {let localText = NSLocalizedString (key, tableName: "Localizable", bundle: localizedBundle, comment: "") return localText = key? Comment: localText}

Code Description:

1. "Localizable" refers to Localizable. strings

2. "zh-Hans" must specify Chinese characters here

3. Use the above Code if specified. Otherwise, you can directly use NSLocalizedString (key, comment: "") to automatically switch between the two based on the system 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.