aboutsummaryrefslogtreecommitdiffstats
path: root/Source/xibLocalizationPostprocessor.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-06-12 15:20:57 +0000
committerrowanbeentje <rowan@beent.je>2010-06-12 15:20:57 +0000
commit1c89992b2af18acb457819b94f50fee247620d28 (patch)
tree7ab7503093ab37b96dd709a70a1180881d7a6fcd /Source/xibLocalizationPostprocessor.m
parent03bdabf809d02a7f76c2fbc02841bb1030c49a47 (diff)
downloadsequelpro-1c89992b2af18acb457819b94f50fee247620d28.tar.gz
sequelpro-1c89992b2af18acb457819b94f50fee247620d28.tar.bz2
sequelpro-1c89992b2af18acb457819b94f50fee247620d28.zip
- Implement the Wil shipley/Golden % Braeburn localisation method for .xibs; add a build stage to Release/Dist builds which generates .strings files for each nib, and swizzle nib loading to automatically translate strings based on any localised .strings files
- Fix the genstring stage of the build script and move it to Release/Dist builds only - Update Localizable.strings to match latest code
Diffstat (limited to 'Source/xibLocalizationPostprocessor.m')
-rw-r--r--Source/xibLocalizationPostprocessor.m62
1 files changed, 62 insertions, 0 deletions
diff --git a/Source/xibLocalizationPostprocessor.m b/Source/xibLocalizationPostprocessor.m
new file mode 100644
index 00000000..591e92b7
--- /dev/null
+++ b/Source/xibLocalizationPostprocessor.m
@@ -0,0 +1,62 @@
+// xibLocalizationPostprocessor.m
+//
+// Created by William Shipley on 4/14/08.
+// Copyright © 2005-2009 Golden % Braeburn, LLC.
+
+#import <Cocoa/Cocoa.h>
+
+
+int main(int argc, const char *argv[])
+{
+ NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init]; {
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s inputfile outputfile\n", argv[0]);
+ exit (-1);
+ }
+
+ NSError *error = nil;
+ NSStringEncoding usedEncoding;
+ NSString *rawXIBStrings = [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:argv[1]] usedEncoding:&usedEncoding error:&error];
+ if (error) {
+ fprintf(stderr, "Error reading %s: %s\n", argv[1], error.localizedDescription.UTF8String);
+ exit (-1);
+ }
+
+ NSMutableString *outputStrings = [NSMutableString string];
+ NSUInteger lineCount = 0;
+ NSString *lastComment = nil;
+ for (NSString *line in [rawXIBStrings componentsSeparatedByString:@"\n"]) {
+ lineCount++;
+
+ if ([line hasPrefix:@"/*"]) { // eg: /* Class = "NSMenuItem"; title = "Quit Library"; ObjectID = "136"; */
+ lastComment = line;
+ continue;
+
+ } else if (line.length == 0) {
+ lastComment = nil;
+ continue;
+
+ } else if ([line hasPrefix:@"\""] && [line hasSuffix:@"\";"]) { // eg: "136.title" = "Quit Library";
+
+ NSRange quoteEqualsQuoteRange = [line rangeOfString:@"\" = \""];
+ if (quoteEqualsQuoteRange.length && NSMaxRange(quoteEqualsQuoteRange) < line.length - 1) {
+ if (lastComment) {
+ [outputStrings appendString:lastComment];
+ [outputStrings appendString:@"\n"];
+ }
+ NSString *stringNeedingLocalization = [line substringFromIndex:NSMaxRange(quoteEqualsQuoteRange)]; // chop off leading: "blah" = "
+ stringNeedingLocalization = [stringNeedingLocalization substringToIndex:stringNeedingLocalization.length - 2]; // chop off trailing: ";
+ [outputStrings appendFormat:@"\"%@\" = \"%@\";\n\n", stringNeedingLocalization, stringNeedingLocalization];
+ continue;
+ }
+ }
+
+ NSLog(@"Warning: skipped garbage input line %d, contents: \"%@\"", lineCount, line);
+ }
+
+ if (outputStrings.length && ![outputStrings writeToFile:[NSString stringWithUTF8String:argv[2]] atomically:NO encoding:NSUTF8StringEncoding error:&error]) {
+ fprintf(stderr, "Error writing %s: %s\n", argv[2], error.localizedDescription.UTF8String);
+ exit (-1);
+ }
+ } [autoreleasePool release];
+} \ No newline at end of file