iOS Multi-language support

Source: Internet
Author: User

The addition of multi-language support in XCODE4 is not quite the same as the previous version, so here is a brief introduction.

One, find the supporting Files in your project, right-click on it, find the blue highlight as shown below.

Note that you have seen the multiple language support files that I generated, which you did not add here before!!!!

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ 3174f5fafbedab64e672c57af736afc378311e81.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" 3174f5fafbedab64e672c57af736afc378311e81 "/>

Two, as below, select the resource file under the iOS directory to locate the string file selection.

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ 5b602317fdfaaf51729109058c5494eef11f7a93.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" 5b602317fdfaaf51729109058c5494eef11f7a93 "/>

Third, the new file named Localizable, this is certain, can not be named for other names. Be careful here. When you're done, open inspector, check localizable.strings, and you'll see the interface shown below.

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ 75852724bc315c60b8f3e3558db1cb13485477a7.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" 75852724bc315c60b8f3e3558db1cb13485477a7 "/>

Four, find localization, click on the lower left corner of the + button as follows: Add the language support you want.

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ B3ece7ef3d6d55fb949afe9c6d224f4a21a4ddad.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" B3ece7ef3d6d55fb949afe9c6d224f4a21a4ddad "/>

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ C63845f3b2119313e62b770a65380cd790238d99.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" c63845f3b2119313e62b770a65380cd790238d99 "/>
Five, the resulting language files are as follows:

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ D358b7f6905298225d75b179d7ca7bcb0b46d447.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" d358b7f6905298225d75b179d7ca7bcb0b46d447 "/>

At this point you will find the following file directories under your project file: Each file directory has a corresponding language file support. All you need to do now is to add string support to these corresponding files. Finally call nslocalizedstring (@ "String2", nil) in the code where you want to set the string, and the method displays the string and writes everything.

650) this.width=650; "Src=" http://hiphotos.baidu.com/yunhuaikong/pic/item/ 9faadcd8f2d3572c095714668a13632763d0c354.jpg "style=" border:0px;margin-bottom:8px;clear:both;vertical-align:top ; "alt=" 9faadcd8f2d3572c095714668a13632763d0c354 "/>

Examples are as follows: Localizable.strings (中文版)

"Demotitle" = "This is 中文版 Version";
"String1" = "Apple";
"String2" = "BAnana";
"String3" = "Orange";
"String4" = "watermelon";
"String5" = "strawberry";


Localizable.strings (ZH_CN)
"Demotitle" = "This is the Chinese version";
"String1" = "Apple";
"String2" = "banana";
"String3" = "orange";
"String4" = "watermelon";
"String5" = "strawberry";
Code:
MultiLanguageDemoViewController.h



#import <UIKit/UIKit.h>

@interface Multilanguagedemoviewcontroller:uiviewcontroller {
Iboutlet UILabel *lbldemotitle;
Iboutlet UILabel *lblstr1;
Iboutlet UILabel *lblstr2;
Iboutlet UILabel *LBLSTR3;
Iboutlet UILabel *LBLSTR4;
Iboutlet UILabel *LBLSTR5;
}

@property (Nonatomic,retain) UILabel *lbldemotitle;
@property (Nonatomic,retain) UILabel *lblstr1;
@property (Nonatomic,retain) UILabel *lblstr2;
@property (Nonatomic,retain) UILabel *LBLSTR3;
@property (Nonatomic,retain) UILabel *LBLSTR4;
@property (Nonatomic,retain) UILabel *LBLSTR5;

@end
Multilanguagedemoviewcontroller.m
#import "MultiLanguageDemoViewController.h"

@implementation Multilanguagedemoviewcontroller

@synthesize LBLDEMOTITLE,LBLSTR1,LBLSTR2,LBLSTR3,LBLSTR4,LBLSTR5;

-(void) Viewdidload {
[Super Viewdidload];

System settings get multi-language strings
Lbldemotitle.text=nslocalizedstring (@ "Demotitle", nil);
lblstr1.text= nslocalizedstring (@ "String1", nil);
Lblstr2.text=nslocalizedstring (@ "String2", nil);
Lblstr3.text=nslocalizedstring (@ "String3", nil);
Lblstr4.text=nslocalizedstring (@ "String4", nil);
Lblstr5.text=nslocalizedstring (@ "String5", nil);
}


2. Internationalization of Xib files

Add multilingual versions of Get info on Xib files that require internationalization
Modify the corresponding language version of the interface text and pictures.
Simulator test Remember to restore the original factory settings on the simulator, Xcode should clean it, otherwise it may be wrong.


International Code query: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm


3. Program name Internationalization
Create a new Infoplist.strings file
Then internationalize it, get info.
Write the Cfbundledisplayname= "Chinese name" in the language file generated below;
Then edit Info.plist, add a new property application has localized display name, set its type to Boolean, and set its value to checked.



Where strings are used in a program, you can call nslocalizedstring to take out the corresponding language string

If your strings file is not a standard localizable.strings, let's say my.strings can be used

Nslocalizedstringfromtable (@ "button" @ "my", nil), to get the string

iOS Multi-language support

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.