How to enable your iPhone to support multi-language Environments

Source: Internet
Author: User
Tags custom name

We know that the cocoa program fully supports multiple languages, including those in the iPhone. Here is a brief introduction to how to create a multi-language iPhone program. It is also the best way to display Chinese characters on the iPhone. This method is applicable to both toolchain and the official SDK.

I. xcode supports multiple languages
If you use xcode, the method is very simple:

Right-click the project and choose add> new file.

Select strings file in the list

It can be called localizable. strings or another name, such as MyApp. Strings.

Select MyApp. String, press command + I, and click make file localizable in the lower-left corner. You will see that English is already available in localizations in general.

Click Add localization below to add a zh_cn (Simplified Chinese) and a zh_tw or zh_hk (Traditional Chinese ). Note that zh_hans (Simplified Chinese) and zh_hant (Traditional Chinese) can be correctly recognized on Mac, but cannot be correctly recognized on iPhone.

If you want to support other languages, you can add:

Japanese: Japan
German: German
Spanish: Spanish
French: French

The content of the. Strings file can be in the standard plist format or the old list format:

 

<? XML version = "1.0" encoding = "UTF-8"?>

<! Doctype plist public "-// Apple Computer // DTD plist 1.0 // en" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<Plist version = "1.0">

<Dict>

<Key> mykey </key>

<String> myvalue </string>

....

</Dict>

</Plist>

If you want to wrap a string, press enter to wrap it. Do not write it as/n.

Or you can directly use the old list format:

"Mykey" = "myvalue ";

...

Note the plus points after each line.

If you are using localizable. strings, you can obtain the string in the program as follows:

Nslocalizedstring (@ "mykey", nil)

 

If you are using the custom name. Strings, such as MyApp. strings, you can obtain the string in the program as follows:

 

Nslocalizedstringfromtable (@ "mykey", @ "MyApp", nil)

 

In this way, the string "myvalue" can be obtained in any language.

 

If you are using the official iPhone SDK, you can directly use this. strings in the project. If you are using the toolchain, You need to modify the makefile:

 

Add

 

Lang_files = $ (wildcard *. lproj)

Lang_files_abs = $ (addprefix $ (srcroot)/, $ (lang_files ))

Resources = Resources

 

Find

 

$ (App_abs): $ (infoplist_abs)

 

Add the following in the last line:

 

CP-r $ (lang_files_abs) $ (app_abs)/$ (resources)

 

This allows your iPhone to support multi-language environments. Of course, if you are not in trouble, you can also copy these. lproj directories to the compiled bundle.

2. Support for iPhone multi-language Environments in other development environments

If you use Windows or Linux to compile the iPhone toolchain, You need:

 

Create a resources directory in the bundle (for example, MyApp. app directory) of the compiled iPhone program, and then create the following directories respectively:
English. lproj/
Zh_cn.lproj/
Zh_tw.lproj/
....

Put a. Strings file in the directory of each language. For example, MyApp. strings is saved as UTF-8 encoding (file names must be consistent in directories of different languages)

The method for obtaining strings is the same as above. You can also modify the makefile to automatically copy the directories of the. Strings resource file to the bundle of the program during compilation.

In addition, in the iPhone program, the Language Resource directory can be either placed in the resources directory or directly placed in the bundle.

The advantage of this method is obvious: Because the iPhone OS already has built-in multi-language support, why not make your program more usable? In addition, this can avoid the problem of garbled characters in the traditional @ "Chinese" Display (because the nsstring creation method only supports 7-bit ASCII code ).

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ttth202507/archive/2011/04/13/6320284.aspx

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.