IPhoneApplicationsMultiple LanguagesSupported operations are described in this article. There are several concepts: multi-language support, that is, a program supports interfaces in several languages; localization/InternationalizationIs to translate the original language support into another language.
Here we will export several other questions,
1. Support Programs with files in several languages
Ii. How to switch the interface during running
3. Can I retrieve the corresponding characters in the code?
First, let's take a look.IphoneLanguage settings. Open Settings --> International --> Language. You can switch the Language on the interface. You can switch the current Language interface to a different Language.
How does an application perform corresponding switching? If the program has the corresponding language support. Then switch over. If not. The default language is used.
In another case, when the iphone is set to a Chinese interface, the program is manually switched to English. What should we do?
I. language files of the iphone Project
In iphone xcode projects, there are usually several languages supported.
The supported texts of each language are stored in <language type>. lproj/Localizable. strings. For example
In English. lproj/Localizable. strings, the simplified Chinese is in Zh_cn.lproj/Localizable. strings
Localizable. strings can be formatted in either of the following formats:
- "_ LocaleLanguage" = "zh ";
- "Cancel" = "cancel ";
The other is the plist file in XML format.
- <? Xml version = "1.0" encoding = "UTF-8"?>
-
- <! DOCTYPE plist PUBLIC "-// Apple Computer // dtd plist 1.0 // EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-
- <Plist version = "1.0">
- <Dict>
- <Key> button </key>
- <String> buttons </string>
- </Dict>
- </Plist>
2. Operate the strings file in XCode.
What are the detailed operations in XCode?
Http://www.skylarcantu.com/blog/2009/08/19/localization-your-iphone-os-applications-in-xcode/
In the File --> New file on the main menu or the right of the Project window, select Add New ..
In the other file, select create strings File
New files can be stored in any directory, but it is best to write the name Zh_cn.lproj/Localizable. strings as follows:
Manually add translation entries to new files
Repeat the preceding steps for the new language.
3. Use international strings in applications
In a program, you can call NSLocalizedString to retrieve the strings of the corresponding language.
If your strings file is not the standard Localizable. strings file, you can use
NSLocalizedStringFromTable (@ "button", @ "my", nil );
For example, I change the title to an international language.
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"title",nil)
- message:self.textField.text
- delegate:nil cancelButtonTitle:@"OK!"
- otherButtonTitles:nil];
4. display on the Interface
The display on the Interface depends mainly on two points. One is the display language of the current iphone. If it matches, the corresponding language is automatically called.
If the current language application is not supported, the language specified by Localization native development re in Info. plist is automatically displayed.
If the language support in the current application does not match the current one. For example, if the app is in French, German, and Italian, but the iphone is in Spanish, then the app can specify the language at any time to show the French.
How to display the specified language in the program? (To be tested)
Here is a solution. The following is a Language class for setting the current Language. The setting method is setLanguage.
Initialize is used to obtain the current language
- @implementation Language
-
- static NSBundle *bundle = nil;
-
- +(void)initialize {
- NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
- NSArray* languages = [defs objectForKey:@"AppleLanguages"];
- NSString *current = [[languages objectAtIndex:0] retain];
- [self setLanguage:current];
-
- }
-
- /*
- example calls:
- [Language setLanguage:@"it"];
- [Language setLanguage:@"de"];
- */
- +(void)setLanguage:(NSString *)l {
- NSLog(@"preferredLang: %@", l);
- NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
- bundle = [[NSBundle bundleWithPath:path] retain];
- }
-
- +(NSString *)get:(NSString *)key alter:(NSString *)alternate {
- return [bundle localizedStringForKey:key value:alternate table:nil];
- }
- @end
Class calls in the program
Summary:IPhoneApplicationsMultiple LanguagesThe content of the supported operations has been introduced. I hope this article will help you!