iphone 多国语言 設計, multi-language

iphone 多国语言 設計, multi-language

多国语言版本设计示范

说明:依系统设定的语言自动切换适合的显示字串  
操作:


在Interface Builder设计时的介面


若系统设定为English则显示英文介面 


若系统设定为繁体中文则显示为中文介面

如何建立自定的语系档:
1.在Resources分类下新增档案[右键/Add/New File...]
2.在范本的分类选择Other后再选择Strings File


3.将存档档名设定为 Localizable.strings


4.在Localizable.strings 档案上按右键并选择Get Info


5.选择左下方的 Make File Localizable


6.将分页标签切换至General


7.选择左下方的 Add Localization


8.输入新的语系名称 zh_TW 后按 Add  ( 中文简体 Localizable.strings (zh_CN))


9.您会看到目前您设定了English及zh_TW两种语系


10.在档案清单中您将看到Localizable Strings (English) 及Localizable String (zh_TW)


11.开启后编辑语言字串就可以啰,范例如下:
Localizable.strings (English)

/*
Localizable.strings
MultiLanguageDemo

Created by babyfish0226 on 2009/3/6.
Copyright 2009 __MyCompanyName__. All rights reserved.
*/

"DemoTitle"="This is English Version";
"String1"="Apple";
"String2"="BAnana";
"String3"="Orange";
"String4"="Watermelon";
"String5"="Strawberry";

Localizable.strings (zh_TW)

/*
Localizable.strings
MultiLanguageDemo

Created by babyfish0226 on 2009/3/6.
Copyright 2009 __MyCompanyName__. All rights reserved.
*/
"DemoTitle"="這是繁體中文的版本";
"String1"="蘋果";
"String2"="香蕉";
"String3"="橘子";
"String4"="西瓜";
"String5"="草莓";

程式碼:
MultiLanguageDemoViewController.h
//
//  MultiLanguageDemoViewController.h
//  MultiLanguageDemo
//
//  Created by babyfish0226 on 2009/3/6.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#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];

//系統設定取得適合的多國語言字串
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);
}

  • 教學 718
  • 柯博文個人 356