Internationalization of iOS Apps

Source: Internet
Author: User
Tags uikit

Internationalization of iOS applications: preparation for internationalization of programs

1, first we have to create a project, we give him the name Internationalization-demo, and then add the language.

To detach text from your code:

Currently, all the text shown in the app is in Main.storyboard and viewcontroller with hard-coded strings. In order to localize these strings, you need to put them in a separate file. Instead of hard-coding in your method, he will simply refer to these strings in the package.
Xcode uses files with the. strings extension to store and retrieve all the strings used in the app to support each language. Depending on the language currently used by the iOS device, a simple method call in the code will find and return the required string.

2. Create a file with a. strings extension
Open File > New > File, select Strings Fils in Resource,
Click Next, name the file infoplist.strings, and then click Save.


3. After creation, you can see the project directory structure file as follows, click Infoplist.strings, view the properties on the right, and add the language in the localizable bar.


4. After adding, open the corresponding language files, such as
Add to 中文版:
Cfbundledisplayname = "Hello World";

Additions to the Chinese:
Cfbundledisplayname = "Hello World";


5, run, if your simulator is in Chinese, you will see your program name into the world Hello


Set the language to English in the settings and you will see your program name turned into Hello World

Ii. Internationalization of content

1. Create a new Localizable.strings file (Localizable.strings is the system default name)
2. Add language Ibid.
3. Add language content
In Localization.strings, follow the format of "key" = "value" and then use Nslocalizedstring (@ "key", @ "") to read the contents; If it is not used with the system default name
Localization.strings 中文版 File added

"Student" = "Students";

Localization.strings Chinese file added

"Students" = "student";

See my demo for details:
  viewcontroller.h//  Program internationalization////  Created by Dllo on 16/3/24.//  copyright©2016 year Haiteng. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller@end
viewcontroller.m//program Internationalization////Created by Dllo on 16/3/24.//copyright©2016 year 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:@ "student", @ "teacher", @ "Family", @ "classmate", @ "Girlfriend", 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"]; Head View 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  program internationalization  Created by Dllo on 16/3/24.  COPYRIGHT©2016 year Haiteng. All rights reserved.*/"student" = "Students"; " Teacher "=" the Teacher ";" Family "=" Family ";" Classmate "=" Students ";" Girlfriend "=" Girlfriend ";" Image "=" aa.gif ";

Internationalization of iOS Apps

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.