IOS development: a multilingual Method for Applications

Source: Internet
Author: User

It is quite easy to implement the application multilingual in xcode. For most applications, the multi-language mainly lies in the multi-language of text. Other forms and interfaces are generally not involved in multi-language applications. Of course, these can be implemented in xcode. The following describes how to enable multilingual text.


Step 1: Add a multi-language version for the Application


This is very simple. There is localizations under info in the project. Click + to add the required version. A dialog box is displayed, showing the content of the language version to be added.


Storyboard and infoplist. strings are included here. To make the product name multilingual, it should contain infoplist. Strings. At the same time, we can also see that we can directly implement buttons and images in storyboard in multiple languages. Localizable. strings is a multi-language for text, which will be discussed below. You need to add this manually.


Step 2: programming changes

To implement multiple languages, you cannot directly use nsstring in programming. Instead, you can use

Nslocalizedstring (Key, comment)

Basic usage: the key is the nsstring corresponding to the display, and the comment is the comment. The basic principle is that there are different versions of localizable. Strings. The keys of the same annotations are different in different language versions. In this way, different languages are displayed on different language interfaces.


Step 3: Obtain localizable. Strings

Open the terminal:

Change the address to the project folder. The basic method is to enter "cd" and then pull the project folder into its window.

Enter genstrings./localizeme/*. M. localizeme is the project name in my example. Change it to the name of your project. Press enter and open the project folder. Then you can see the localizable. Strings file and pull it into the xcode project.


Open the file and you can see the following similar content. localizable. Strings contains all the content using nslocalizedstring in your project.


The comment here is comment, and the following "three" = "three", the string on the left is the key.


Step 4: Edit localizable. Strings

It doesn't matter if you haven't made the localizable. Strings file multilingual. For example:

Click the file and open the property. The Localization Option is displayed on the right. For example, if you want to add a Chinese version, you can check the Chinese version. In this way, a Chinese version is automatically added to the file.


Next, click the Chinese version to edit it:


It is okay to change the content of each corresponding key to Chinese.

Now run the program. If the mobile phone is Chinese, it displays Chinese content. If it is English, it is English content.


Step 5: Multilingual application names

In infoplist. Strings, enter

Cfbundledisplayname = "Application name ";

You can.


The above is the most basic method to achieve multi-language. Further, there are also multilingual data types, such as currency and time, which need further research!





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.