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.