iOS localization App

Source: Internet
Author: User
Tags uikit

The BK project has been completed in 7788 and will need to be translated into multi-lingual versions at the end of the project. In order to adapt to many countries around the world to use multiple storage.

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, or to generate a different language version number for the same xib file. such as Mainvc.xib (German) and Mainvc.xib (中文版). 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 any other translated "translation" that can be replaced with Google Translate or replace all vowels 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 clear point in time to freeze the UI during the application development cycle. After this, we must resolutely eliminate the change of resources that will affect localization. The nib file can be locked in Xcode. To prevent changes to localizable properties, non-localizable properties, or all properties, as seen. Then send the text you want to translate to a translator or a localization service provider to translate it.


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

(4) Version number control Use the version number control system to record every change you made.

(5) test not how to say, necessary steps.

(6a) Merging logical change logic changes generally does not affect nib files and localization work. A multi-person collaborative project still needs to incorporate some change logic.

(6b) Localization changes Assuming you've made some localized changes, such as changing the localized text, you need to start the process from scratch. and send these changes to the local staff. The ability to reuse previous string translations can be much more efficient, but still very cumbersome. Therefore, you should try to avoid introducing such changes in the late stages of development.

There have been a lot of Daniel's written before applying localized articles. Here is not to repeat, directly posted I read the thought 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 used storyboard.

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

Other than that. The point is to talk about a class I found on GitHub, great, elegant code that moved to my tears. DC ~ ~

This is the project address on GitHub: here, let's say you have a lot of other good code to find.

As the author has said:



The following is the ohautonibi18n.m class. Made a small change, without changing the frame. The font size of UILabel, UIButton and Uitextfield has been adaptively adjusted.

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, you need to pay attention to:

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

2, do not casually if 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 ~


Articles:

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

Localization Collaboration tool: https://www.transifex.com/product/

https://crowdin.com/



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

iOS localization App

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.