1、首先我们要先创建一个工程,我们给他命名Internationalization-Demo,然后添加语言。

目前,应用展示的所有文本都是以硬编码字符串存在于Main.storyboard 和 ViewController里。为了本地化这些字符串,你需要把它们放在一个单独的文件中。他将会在包中简单地引用这些字符串,而不是在你的方法中进行硬编码。
Xcode使用带有 .strings 扩展名的文件来存储和检索app中使用的所有字符串,以支持每种语言。根据iOS 设备当前使用的语言,代码中一个简单的方法调用将会查找并返回要求的字符串。
2、创建一个.strings 扩展名的文件
打开File > New > File,选择Resource中Strings Fils,如图:
点击下一步,为文件命名为InfoPlist.strings,然后点击save。

3、创建完成后,你可以看到工程目录结构文件如下,单击InfoPlist.strings,查看右边的属性,在Localizable栏添加语言。如图

4、添加完成后打开对应语言文件,比如
English的添加:
CFBundleDisplayName = "hello world";
Chinese的添加:
CFBundleDisplayName = "世界 你好";

5、运行,如果你的模拟器是中文的,你会看到你的程序名称变成了 世界 你好

在设置中把语言设置成英文的,你就会看到你的程序名称变成了 hello world

1、新建一个Localizable.strings 文件 (Localizable.strings 是系统默认名字)
2、添加语言同上
3、添加语言内容
在Localization.strings 中,按照"key" = "value"的格式;然后使用时用NSLocalizedString(@"key", @"")读取内容; 如果不是用系统默认名字那么使用
Localization.strings English 文件添加
"学生" = "Students";
Localization.strings Chinese 文件添加
"Students" = "学生";
// // ViewController.h // 程序国际化 // // Created by dllo on 16/3/24. // Copyright © 2016年 HaiTeng. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
//
// ViewController.m
// 程序国际化
//
// Created by dllo on 16/3/24.
// Copyright © 2016年 HaiTeng. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UIImageView *tableHeaderView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.dataArray =[NSMutableArray arrayWithObjects:@"学生", @"老师", @"家人", @"同学", @"女朋友", nil];
self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_id"];
//头视图
self.tableHeaderView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 100)];
NSString *str = NSLocalizedStringFromTable(@"image", @"Table", nil);
self.tableHeaderView.image = [UIImage imageNamed:str];
self.tableView.tableHeaderView = self.tableHeaderView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_id"];
cell.textLabel.text = NSLocalizedStringFromTable(self.dataArray[indexPath.row], @"Table", nil);
return cell;
}
@end
////////////////////////////////////////////////////////////////////////////
/* Table.strings 程序国际化 Created by dllo on 16/3/24. Copyright © 2016年 HaiTeng. All rights reserved. */ "学生" = "Students"; "老师" = "The teacher"; "家人" = "Family"; "同学" = "Students"; "女朋友" = "GirlFriend"; "image" = "aa.gif";
原文:http://www.cnblogs.com/HaiTeng/p/5323729.html