#Hassle Free Localization
After all these try-and-error, here're my new requirements:
- Fully automatic and reflect to current code. ( because we, developers, are lazy )
- Only ONE set of XIB/NIB is used.
- Ease of localization. ( one master localization strings file )
The flow becomes
genstrings
to make masterLocalization.strings
ibtool
to extract localizable values- merge 1 and 2 with up-to-date localization
C3PO is dedicated to automate this flow. All you need to do is meeting following requirements
##Create a new build phase
find ${SRCROOT} -name "Localizable.strings" -print | xargs -I {} echo "iconv -f UTF-8 -t UTF-16 =(cat {})> {}" | zsh
python ${SRCROOT}/externals/C3PO/localize.py
find ${SRCROOT} -name "Localizable.strings" -print | xargs -I {} echo "iconv -f UTF-16 -t UTF-8 =(cat {})> {}" | zsh
##Use NSLocalizedString for all UI strings
myLabel.text = NSLocalizedString(@"MY_TEXT", nil);
##Use WIDE_CASE or CamelCase in Interface Builder
<string key="IBUIText">MY_TEXT</string>
or
<string key="IBUIText">MyTest</string>
##Add following lines to your controller
- (void) viewDidLoad {
for (UILabel *aLabel in self.interfaceLabels) {
aLabel.text = NSLocalizedString(aLabel.text, @"C3PO Localized");
}
##Your localization string is ready to go
% find . -name "Localizable.strings"
./en.lproj/Localizable.strings
./zh-Hant.lproj/Localizable.strings
Time to take your app to the world. @jamex