Skip to content
Newer
Older
100644 53 lines (26 sloc) 4.23 KB
c249877 @AliSoftware ReadMe updated
authored
1 # What's this
2
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
3 This class allows you to **automate the internationalisation** (i18n) of your interface (XIB files) **without any additional code in your application**. No more using multiple XIBs for various locales or having outlets just to translate the text of a label!
c249877 @AliSoftware ReadMe updated
authored
4
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
5 Simply use the keys of your Localizable.strings in the text of any element in your XIB
6 (title of an `UIButton`, text of a `UILabel`, …), and it will be automatically translated on the fly at runtime!
c249877 @AliSoftware ReadMe updated
authored
7
8 * You don't need to have one XIB file by language/locale any more!
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
9 * You don't need to have an `IBOutlet` to all of your XIB objects just to translate their text manually by code with `NSLocalizedString`!
c249877 @AliSoftware ReadMe updated
authored
10
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
11 > Note: strings starting with a digit won't be translated. This is a feature used to avoid useless translation of static numbers you put in your XIB (especially because you will probably change this "0.00" string in your XIB with some real value by code later)
c249877 @AliSoftware ReadMe updated
authored
12
13
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
14 # Installation
c249877 @AliSoftware ReadMe updated
authored
15
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
16 To use this, simply **add `OHAutoNIBi18n.m` in your project** and… that's all! `OHAutoNIBi18n` will be loaded automatically at runtime and translate your XIB on the fly without any additional line of code.
c249877 @AliSoftware ReadMe updated
authored
17
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
18 If you also want to use the `_T()`, `_Tf()` and `_Tfn()` macros, you can also add and `#import "OHL10nMacros.h"`.
c249877 @AliSoftware ReadMe updated
authored
19
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
20 Alternatively, you can install all of it using CocoaPods. Simply add `pod "OHAutoNIBi18n"` to your `Podfile`.
c249877 @AliSoftware ReadMe updated
authored
21
22
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
23 # Debugging your unlocalized strings
24
25 You can `#define OHAutoNIBi18n_DEBUG 1` if you want `OHAutoNIBi18n` to warn every time it encounters a string for which it does not find any translation in your `Localizable.strings` file. In that case, it will log a message in your console and add the `$` character around the text in your XIB at runtime so you can easily see it.
26
8934ba1 @AliSoftware Changed auto-load code location to avoid the “unrecognized selector” …
authored
27 > Note that you can use strings starting with a "." in your XIB (like ".Lorem ipsum dolor sit amet" to avoid warnings on those strings when `OHAutoNIBi18n_DEBUG` is set. This is useful for strings you use only as "layout helpers" (dummy strings to help you see your label in your XIB, which is easier than an empty label to help you position it), like for a `UILabel` in a custom `UITableViewCell` for which you don't want those warnings, knowing that you will override its text by code anyway.
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
28
29
bb55b6b @AliSoftware Updated README
authored
30 # How it works
31
8934ba1 @AliSoftware Changed auto-load code location to avoid the “unrecognized selector” …
authored
32 This class uses method swizzling to intercept the calls to `awakeFromNib` and automatically localize any object created/extracted from a XIB file by the runtime. The method swizzling is done automatically when your application is loaded in memory, so you don't even have to add code to install this: the only presence of the OHAutoNIBi18n.m file in your project makes everything magic!
bb55b6b @AliSoftware Updated README
authored
33
34
35 ### Comparison with Xcode 4.5's "Base Localization"
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
36
37 Starting with Xcode 4.5, you can use the "Base Localisation" (see [Apple Tutorial: Internationalize your application](https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.html)).
38
8934ba1 @AliSoftware Changed auto-load code location to avoid the “unrecognized selector” …
authored
39 But this process requires that you create a `*.strings` file for each of your XIB files, with the same name as the XIB file, and that you rely on Interface Builder's "Object IDs" which are fare from descriptive and human-readable.
128ce1d @AliSoftware Refactoring to rename to OHAutoNIBi18n and prepare to Podify
authored
40
41 This can become quite a pain:
42
43 * If you have a lot of XIB files, you will have to create as many `.strings` files, resulting in a lot of files
8934ba1 @AliSoftware Changed auto-load code location to avoid the “unrecognized selector” …
authored
44 * With Base Localization, your `.strings` files will use abstract Object IDs, which are far from convenient to identify objects of your XIB (not even mentioning when you need to provide those `Localizable.strings` files to the person you pay to translate your application, how will s/he understand how to match those IDs with the actual UI?)
bb55b6b @AliSoftware Updated README
authored
45 * This is also problematic for every generic term in your application that is used across multiple XIB, like some vocabulary or strings specific to your application domain and used in all of your XIB files. In that case, Base Localization requires that you repeat this term in every of your `.strings` files, whereas with `OHAutoNIBi18n` you can just translate it once in your `Localizable.strings`.
46
8934ba1 @AliSoftware Changed auto-load code location to avoid the “unrecognized selector” …
authored
47 For all these reasons, Base Localization is just not such a great solution after all, whereas `OHAutoNIBi18n` does not have those quirks.
48
49
bb55b6b @AliSoftware Updated README
authored
50 # License
51
52 This code is distributed under the MIT License.
Something went wrong with that request. Please try again.