IOS study notes 23-iOS Internationalization

Source: Internet
Author: User

 


1. Create a Windows-base Application. Open the main. m file and add the following code to the main function:

// Obtain the default user information

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

// Obtain all language settings supported by the iPhone

NSArray * ages = [defaults objectForKey: @ "AppleLanguages"];

NSLog (@ "% @", ages );


3. Use NSLocalizedString in source code to reference international files


// The first parameter in the brackets is the content to be displayed, which corresponds to the IDs in each Localizable. strings.
// The second parameter is a comment on the first parameter, which can be a null string.
[_ AlertView setTitle: NSLocalizedString (@ "Submittedsuccessfully", @ "")];
4. Use the Terminal genstrings command to generate a resource file
Open Terminal, cd to the directory where the project is located, and use genstrings to generate the source file automatically generated from the source code.
For example, if the project directory is/user/project/test01, the command is as follows:


Genstrings-o English. lproj./classes/*. m
Genstrings-o zh. lproj./classes/*. m
5. Edit the Localizable. strings files.
In step 4, we get the resource file corresponding to the code. Finally, we need to translate these resource files into the corresponding language. for example, in Localizable. in strings (zh), compile the text after the equal sign into Chinese.


"Submitted successfully" = "Submitted successfully"
After the project is re-compiled, the corresponding language is displayed in different language environments.

 

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.