IOS Localization Application
The BK project has been completed in. Later versions of the project need to be translated into multi-language versions to adapt to the use of multiple stores in multiple countries around the world.
Application localization is to localize strings, images, and xib or storyboard files respectively. The traditional approach is to associate a variable with strings on xib (including UILabel, UIButton, UITextField, and so on ).NSLocalizedStringThis function is used to find Localizeable. the key value in the strings file is localized, or different language versions of the same xib file are generated, such as MainVC. xib (German) and MainVC. xib (English), but it is too complicated to do so, as people often say tedious and useless.
Let's first introduce the general process of Localization:
(1) pseudo-localizationPseudo-localization is the process of localized strings into meaningless languages. To replace the string to be translated with another assumption that it is already a translated "Translation", you can use Google Translate to replace it or replace all vowels with x, for example: press here to continue to Prxss hxrx tx cxntxnxx ". This aims to detect problems as soon as possible. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + primary + 9rbFvvi74dOwz + yxvrXYu6 + primary/r/primary + t6K4 + Let0uvIy9Sxu/LV38rHsb612Luvt/primary = "http://www.2cto.com/uploadfile/Collfiles/20140718/2014071809451874.png" alt = "\">
(3) LocalizationAfter resources are sent to the localization service provider, they will send back the translated files. Perform Localization Based on the translated text.
(4) Version ControlUse the version control system to record each of your changes.
(5) testThe required steps.
(6a) Merge logical changesLogical changes generally do not affect the work of nib files and localization. projects that involve multi-person collaboration still need to merge the logic of some changes.
(6b) localization changeIf you have made some localization changes, such as changing the localized text, you need to start the process from scratch and send these changes to the localization personnel. It can reuse the previous string translation, which will greatly improve the efficiency, but it is still very troublesome. Therefore, we should try to avoid introducing such changes later in development.
I have already written many articles about application localization before. I will not repeat them here. I will directly post the articles I have read that are not bad:
1. MJ's application localization, written in 2013. For XCode5, some operation interfaces are different, but the idea remains unchanged.
2. IOS app internationalization tutorial (version 2014), which is relatively new and uses storyboard.
3. Internationalization Tutorial for iOS [2014 Edition] On RAYWENDERLICH all of the above articles are good and worth reading. It is strongly recommended.
In addition, the focus is on a Class I found on github, which is very good. The elegant code has been touched by my tears ~~
This is the project address on github: HERE. If you find more and better code, please let me know.
As the author said:
Below isOHAutoNIBi18n. mClass. without changing the frame, the font size of UILabel, UIButton, and UITextField is adaptive.
/// OHAutoNIBi18n. m /// Created by Olivier on 03/11/10. // Copyright 2010 FoodReporter. All rights reserved. // # import
# Import
Static inline NSString * localizedString (NSString * aString); static inline void localizeUIBarButtonItem (UIBarButtonItem * bbi); static inline void localizeUIBarItem (UIBarItem * bi ); static inline void localizeUIButton (UIButton * btn); static inline void localizeUILabel (UILabel * lbl); static inline void Merge (Bytes * ni); static inline void Merge (UISearchBar * sb ); sta Tic inline void merge (optional * SC); static inline void localizeUITextField (UITextField * tf); static inline void Merge (UITextView * TV); static inline void localizeUIViewController (UIViewController * vc ); // define @ interface NSObject (OHAutoNIBi18n)-(void) localizeNibObject; @ End @ implementation NSObject (OHAutoNIBi18n) # define LocalizeIfClass (Cls) if ([self isKindOfClass: [Cls class]) localize # Cls (Cls *) self) -(void) implements {LocalizeIfClass (region); else LocalizeIfClass (UIBarItem); else LocalizeIfClass (UIButton); else LocalizeIfClass (UILabel); else LocalizeIfClass (UINavigationItem ); else LocalizeIfClass (UISearchBar); else LocalizeIfClass (UISegmentedControl); Else LocalizeIfClass (UITextField); else LocalizeIfClass (UITextView); else LocalizeIfClass (UIViewController); if (self. isAccessibilityElement = YES) {self. accessibilityLabel = localizedString (self. accessibilityLabel); self. accessibilityHint = localizedString (self. accessibilityHint);} // Call the original awakeFromNib method [self localizeNibObject]; // this actually callthe original awakeFromNib (And not localizeNibObject) because we did some method swizzling} + (void) load {// Autoload: swizzle-awakeFromNib with-localizeNibObject as soon as the app (and thus this class) is loadedMethod localizeNibObject = callback ([NSObject class], @ selector (localizeNibObject); Method awakeFromNib = callback ([NSObject class], @ selector (awakeFromNib); callback Tations (awakeFromNib, localizeNibObject );} @ end ////////////////////////////////////// /// // static inline NSString * localizedString (NSString * aString) {if (aString = nil | [aString length] = 0) return aString; // Don't translate strings starting with a digitif ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember: [aString characterAtIndex: 0]) return aString; # If OHAutoNIBi18n_DEBUG # warning Debug mode for i18n is active static NSString * const kNoTranslation = @ "$! "; NSString * tr = [[NSBundle mainBundle] localizedStringForKey: aString value: kNoTranslation table: nil]; if ([tr isw.tostring: kNoTranslation]) {if ([aString hasPrefix: @". "]) {// strings in XIB starting '. 'Are typically used as temporary placeholder for design // and will be replaced by code later, so don't warn about themreturn aString ;} NSLog (@ "No translation for string '% @'", aString); tr = [N SString stringWithFormat: @ "$ % @ $", aString];} return tr; # elsereturn [[NSBundle mainBundle] localizedStringForKey: aString value: nil table: nil]; # endif} // define static inline void encode (UIBarButtonItem * bbi) {localizeUIBarItem (bbi);/* inheritence */NSMutableSet * locTitles = [[NSMutableSet alloc] InitWithCapacity: [bbi. possibleTitles count]; for (NSString * str in bbi. possibleTitles) {[locTitles addObject: localizedString (str)];} bbi. possibleTitles = [NSSet setWithSet: locTitles]; # if! _ Has_feature (objc_arc) [locTitles release]; # endif} static inline void localizeUIBarItem (UIBarItem * bi) {bi. title = localizedString (bi. title);} static inline void localizeUIButton (UIButton * btn) {NSString * title [4] = {[btn titleForState: UIControlStateNormal], [btn titleForState: physical], [btn titleForState: UIControlStateDisabled], [btn titleForState: UIControlStateSelected]}; [btn. title Label setAdjustsFontSizeToFitWidth: YES]; [btn setTitle: localizedString (title [0]) forState: UIControlStateNormal]; if (title [1] = [btn titleForState: UIControlStateHighlighted]) [btn setTitle: localizedString (title [1]) forState: UIControlStateHighlighted]; if (title [2] = [btn titleForState: UIControlStateDisabled]) [btn setTitle: localizedString (title [2]) forState: UIControlStateDisabled]; if (title [3] = [bt N titleForState: UIControlStateSelected]) [btn setTitle: localizedString (title [3]) forState: UIControlStateSelected];} static inline void localizeUILabel (UILabel * lbl) {lbl. adjustsFontSizeToFitWidth = YES; // lbl. minimumScaleFactor = 6.0f; lbl. text = localizedString (lbl. text);} static inline void localizeUINavigationItem (UINavigationItem * ni) {ni. title = localizedString (ni. title); ni. prompt = localizedStr Ing (ni. prompt);} static inline void localizeUISearchBar (UISearchBar * sb) {sb. placeholder = localizedString (sb. placeholder); sb. prompt = localizedString (sb. prompt); sb. text = localizedString (sb. text); NSMutableArray * locScopesTitles = [[NSMutableArray alloc] initWithCapacity: [sb. scopeButtonTitles count]; for (NSString * str in sb. scopeButtonTitles) {[locScopesTitles addObject: localizedString (str)];} sb. SC OpeButtonTitles = [NSArray arrayWithArray: locScopesTitles]; # if! _ Has_feature (objc_arc) [locScopesTitles release]; # endif} static inline void Merge (UISegmentedControl * SC) {NSUInteger n = SC. numberOfSegments; for (NSUInteger idx = 0;
Tips:Also required for localizationNote:
1. Do not forget to read the language from the right to the left.
2. Do not simply assume that the comma is a thousands separator and the period is the decimal point. It may be different in different languages.
3. Note the formatting of numbers and dates (both input and output must be formatted ).
Now, the application localization is much simpler, and the rest will be handed over to the translators ~
References:
Official Apple documentation: Localizing your APP
Official Apple documentation: Internationalize Your App
Apple official documentation: Data Formatting Guide
Apple official documentation: Internationalization Programming Topics
Apple official documentation: Internationalization and Localization