Skip to content

Instantly share code, notes, and snippets.

@leejunkit
Last active December 14, 2015 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejunkit/5083119 to your computer and use it in GitHub Desktop.
Save leejunkit/5083119 to your computer and use it in GitHub Desktop.
In this example, I will localize v3.0 of an app for Traditional Chinese (zh-hant) using an existing zh-hant strings file from v2.9 of the app.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
// load the canonical en strings file -- this can be generated with ibtool
NSDictionary *enStrings = [NSDictionary dictionaryWithContentsOfFile:@"v3.0/en.lproj/MainStoryboard.strings"];
// load a localized strings file from the previous version
NSDictionary *prevLocalizedStrings = [NSDictionary dictionaryWithContentsOfFile:@"v2.9/zh-hant.lproj/MainStoryboard.strings"];
// using the keys from the en string file, create a new dictionary
NSMutableDictionary *newLocalizedStrings = [NSMutableDictionary dictionaryWithCapacity:enStrings.count];
for (NSString *key in enStrings) {
NSString *prevLocalizedStringValue = prevLocalizedStrings[key];
if (prevLocalizedStringValue) {
// this is an existing localized string
[newLocalizedStrings setObject:prevLocalizedStringValue forKey:key];
}
else {
// key not found in previous strings file, it's a new localized string for this version
[newLocalizedStrings setObject:enStrings[key] forKey:key];
NSLog(@"Key %@ not found in previous localized strings file", key);
}
}
[newLocalizedStrings writeToFile:@"v3.0/zh-hant.lproj/MainStoryboard.strings" atomically:YES];
// finally, using the NSLog output in the console, note the new localizations which you need to handle manually
NSLog(@"Done!");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment