iOS localization App

Source: Internet
Author: User
Tags uikit version control system

The BK project has been completed in 7788 and needs to be translated into multi-lingual versions at the end of the project to accommodate the use of multiple storefronts in multiple countries around the world.

Applying localization is to localize strings, pictures, and Xib or storyboard files, but it is a traditional practice to associate a variable to a string on xib (including Uilabel and UIButton, Uitextfield, etc.) by Nslocalizedstring This function to locate the key value in the localizeable. strings file for localization operations, or to generate different language versions of the same Xib file, such as Mainvc.xib (German) and Mainvc.xib (English), but this is too complicated, as people often say tedious and useless.


Let's start by introducing the general process of localization:

(1) pseudo-localization Pseudo-localization is the process of localizing a string into a meaningless language. The string to be translated will be replaced with other assumptions already translated "translated", can be replaced with Google Translate or all vowels are replaced with x, for example: "Press here to continue" will become "PRXSS HXRX TX cxntxnxx". The purpose of this is to identify problems as early as possible.

(2) The frozen UI must have a definite point in time to freeze the UI during the application development cycle. After this, we will resolutely eliminate the resource changes that affect localization, nib files can be locked in Xcode to prevent the modification of localizable properties, non-localizable attributes, or all properties, and then send the text that needs to be translated to a translator or a localization service provider.


(3) after localizing the resources to the localization service provider, they will send back the completed documents. Localize your work according to the translated text.

(4) version control uses a version control system to record every change you have made.

(5) The test does not need to say, the necessary steps.

(6a) Merging logical change logic changes will generally not affect the nib file and localization work, the multi-person collaborative project or need to merge some change logic.

(6b) Localization changes If you make some localized changes, such as changing the localized text, you need to start the process from scratch and send the changes to the localizer. The previous string translation can be reused, and doing so will be much more efficient, but still cumbersome. Therefore, you should try to avoid introducing such changes in the late stages of development.

The application of the localization of the article has been a lot of Daniel has written, here is not to repeat, directly posted I read the feel is also good article:

1, MJ's application localization, wrote in 2013, for XCODE5, some interface has been different, but the idea is unchanged.

2, iOS Application internationalization tutorial (2014 version), this is relatively new, and is using storyboard.

3, Raywenderlich on the internationalization Tutorial for IOS [Edition] The above articles are very good, well worth reading, highly recommended.

Also, the point is to talk about a class I found on GitHub, very good, elegant code has been moved to my tears rushing DC ~ ~

This is the project address on GitHub: here, if you find more and better good code, please let me know.

As the author has said:



The following is the ohautonibi18n.m class, made a small change, without changing the frame, the UILabel, UIButton, Uitextfield font size did a bit of self-adaptation.

ohautonibi18n.m////Created by Olivier on 03/11/10.//Copyright foodreporter. All rights reserved.//#import <objc/runtime.h> #import <uikit/uikit.h>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 Localizeuinavigationitem (uinavigationitem* ni), static inline void Localizeuisearchbar (uisearchbar* sb); static inline void Localizeuisegmentedcontrol (uisegmentedcontrol* SC); static inline void Localizeuitextfield (uitextfield* tf), static inline void Localizeuitextview (uitextview* TV), Static inline void Localizeuiviewcontroller (uiviewcontroller* vc);//---------------------------------------------------------- --------------------------------------@interface NSObject (ohautonibi18n)-(void) localizenibobject;@ End@implementation NsobjeCT (ohautonibi18n) #define LOCALIZEIFCLASS (Cls) if ([Self Iskindofclass:[cls class]] localize# #Cls ((cls*) self)-(void) Localizenibobject{localizeifclass (Uibarbuttonitem); 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 calls the original awakefromnib (and not localizenibobject) because we did some method swizzling}+ (void) L oad{//Autoload:swizzle-awakefromnib With-localizenibobject as soon as the app (and thus this class) is Loadedmeth OD localizenibobject = Class_getinstancemethod ([NSObject class], @selector (localizenibobject)); Method awakefromnib = Class_getinstancemethod ([NSObject class], @selector (awakefromnib)); method_ Exchangeimplementations (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 Nsstri ng* Const Knotranslation = @ "$!"; nsstring* tr = [[NSBundle mainbundle] localizedstringforkey:astring value:knotranslation table:nil];if ([tr        Isequaltostring:knotranslation]) {if ([astring hasprefix:@ "."])   {//strings in XIB starting with '. ' is typically used as temporary placeholder for design         And would be is replaced by code later, so don ' t warn about Themreturn astring;} NSLog (@ "No translation for string '%@ '", astring); tr = [NSString stringwithformat:@ "$%@$", astring];} return tr; #elsereturn [[NSBundle mainbundle] localizedstringforkey:astring value:nil table:nil]; #endif}//----------- -------------------------------------------------------------------------------------static inline void Localizeuibarbuttonitem (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:UICONTROLSTATEHIGHLIGHTED],[BTN titleforstate:uicontrolstatedisabled],[btn titleForState:    Uicontrolstateselected]}; [Btn.titlelabel 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] = = [BTN 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 = LocalizedString (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.scopebuttontitles = [Nsarray arraywitharray:locscopestitles]; #if! __has_feature (OBJC_ARC) [Locscopestitles release]; #endif}static inline void Localizeuisegmentedcontrol ( uisegmentedcontrol* SC) {Nsuinteger n = sc.numberofsegments;for (Nsuinteger idx = 0; idx<n; ++idx) {[SC SetTitle:localiz Edstring ([SC Titleforsegmentatindex:idx]) forsegmentatindex:idx];}} static inline void Localizeuitextfield (uitextfield* tf) {tf.adjustsfontsizetofitwidth = Yes;tf.text = LocalizedString ( Tf.text); Tf.placeholder = LocalizedString (Tf.placeholder);} static inline void Localizeuitextview (uitextview* TV) {Tv.text = LocalizedString (Tv.text);} static inline void LocalizeuivieWcontroller (uiviewcontroller* vc) {vc.title = LocalizedString (vc.title);} 

Tips: When localizing, it's important to note:

1. Don't forget to read the language from right to left.

2, do not casually assume that the comma is the thousand separator and the period is the decimal point. may be different in different languages.

3. Note the formatting of numbers and dates (both input and output need to be formatted).

At this point, the application of localization is much easier, the rest of the matter to the translator to go to it ~


Reference article:

Apple Official document: Localizing your APP

Apple Official document: Internationalize Your App

Apple Official Document: Data formatting Guide

Apple Official Document: Internationalization programming Topics

Apple Official document: Internationalization and Localization




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.