diff --git a/Applications/Gorm/GormAppDelegate.h b/Applications/Gorm/GormAppDelegate.h index ea16ec5d..9d29f7c2 100644 --- a/Applications/Gorm/GormAppDelegate.h +++ b/Applications/Gorm/GormAppDelegate.h @@ -85,7 +85,10 @@ - (IBAction) loadPalette: (id) sender; // Translation +- (IBAction) importXLIFFDocument: (id)sender; - (IBAction) exportXLIFFDocument: (id)sender; +- (IBAction) translate: (id)sender; +- (IBAction) exportStrings: (id)sender; // Print - (IBAction) print: (id)sender; diff --git a/Applications/Gorm/GormAppDelegate.m b/Applications/Gorm/GormAppDelegate.m index a7cfa2d7..9cc0fed8 100644 --- a/Applications/Gorm/GormAppDelegate.m +++ b/Applications/Gorm/GormAppDelegate.m @@ -33,6 +33,12 @@ #import "GormAppDelegate.h" #import "GormLanguageViewController.h" +@interface GormDocument (Private) + +- (NSMutableArray *) _collectAllObjects; + +@end + @implementation GormAppDelegate // App delegate... @@ -572,7 +578,65 @@ } // Translation -- (IBAction) exportXLIFFDocument: (id)sender; +- (IBAction) importXLIFFDocument: (id)sender +{ + NSArray *fileTypes = [NSArray arrayWithObjects: @"xliff", nil]; + NSOpenPanel *oPanel = [NSOpenPanel openPanel]; + int result; + + [oPanel setAllowsMultipleSelection: NO]; + [oPanel setCanChooseFiles: YES]; + [oPanel setCanChooseDirectories: NO]; + result = [oPanel runModalForDirectory: nil + file: nil + types: fileTypes]; + if (result == NSOKButton) + { + GormDocument *doc = (GormDocument *)[self activeDocument]; + NSMutableArray *allObjects = [doc _collectAllObjects]; + NSString *filename = [oPanel filename]; + NSEnumerator *en = nil; + id obj = nil; + + NS_DURING + { + [doc importXLIFFDocumentWithName: filename]; + } + NS_HANDLER + { + NSString *message = [localException reason]; + NSRunAlertPanel(_(@"Problem loading XLIFF"), + message, nil, nil, nil); + } + NS_ENDHANDLER; + + [doc touch]; // mark the document as modified... + + // change to translated values. + en = [allObjects objectEnumerator]; + while((obj = [en nextObject]) != nil) + { + if([obj isKindOfClass: [NSView class]]) + { + [obj setNeedsDisplay: YES]; + } + + // redisplay/flush, if the object is a window. + if([obj isKindOfClass: [NSWindow class]]) + { + NSWindow *w = (NSWindow *)obj; + [w setViewsNeedDisplay: YES]; + [w disableFlushWindow]; + [[w contentView] setNeedsDisplay: YES]; + [[w contentView] displayIfNeeded]; + [w enableFlushWindow]; + [w flushWindowIfNeeded]; + } + } + } +} + +- (IBAction) exportXLIFFDocument: (id)sender { NSSavePanel *savePanel = [NSSavePanel savePanel]; NSBundle *bundle = [NSBundle bundleForClass: [GormLanguageViewController class]]; @@ -624,8 +688,93 @@ return filename; } -// Print +/** + * This method is used to translate all of the strings in the file from one language + * into another. This is helpful when attempting to translate an application for use + * in different locales. + */ +- (IBAction) translate: (id)sender +{ + NSArray *fileTypes = [NSArray arrayWithObjects: @"strings", nil]; + NSOpenPanel *oPanel = [NSOpenPanel openPanel]; + int result; + [oPanel setAllowsMultipleSelection: NO]; + [oPanel setCanChooseFiles: YES]; + [oPanel setCanChooseDirectories: NO]; + result = [oPanel runModalForDirectory: nil + file: nil + types: fileTypes]; + if (result == NSOKButton) + { + GormDocument *doc = (GormDocument *)[self activeDocument]; + NSMutableArray *allObjects = [doc _collectAllObjects]; + NSString *filename = [oPanel filename]; + NSEnumerator *en = nil; + id obj = nil; + + NS_DURING + { + [doc importStringsFromFile: filename]; + } + NS_HANDLER + { + NSString *message = [localException reason]; + NSRunAlertPanel(_(@"Problem loading strings"), + message, nil, nil, nil); + } + NS_ENDHANDLER; + + [doc touch]; // mark the document as modified... + + // change to translated values. + en = [allObjects objectEnumerator]; + while((obj = [en nextObject]) != nil) + { + if([obj isKindOfClass: [NSView class]]) + { + [obj setNeedsDisplay: YES]; + } + + // redisplay/flush, if the object is a window. + if([obj isKindOfClass: [NSWindow class]]) + { + NSWindow *w = (NSWindow *)obj; + [w setViewsNeedDisplay: YES]; + [w disableFlushWindow]; + [[w contentView] setNeedsDisplay: YES]; + [[w contentView] displayIfNeeded]; + [w enableFlushWindow]; + [w flushWindowIfNeeded]; + } + } + } +} + +/** + * This method is used to export all strings in a document to a file for Language + * translation. This allows the user to see all of the strings which can be translated + * and allows the user to provide a translateion for each of them. + */ +- (IBAction) exportStrings: (id)sender +{ + NSSavePanel *sp = [NSSavePanel savePanel]; + int result; + + [sp setRequiredFileType: @"strings"]; + [sp setTitle: _(@"Save strings file as...")]; + result = [sp runModalForDirectory: NSHomeDirectory() + file: nil]; + if (result == NSOKButton) + { + NSString *filename = [sp filename]; + GormDocument *doc = (GormDocument *)[self activeDocument]; + + [doc exportStringsToFile: filename]; + } +} + +// Print - (IBAction) print: (id) sender { [[NSApp keyWindow] print: sender]; diff --git a/GormCore/GormDocument.h b/GormCore/GormDocument.h index c9c984ef..14ae91fc 100644 --- a/GormCore/GormDocument.h +++ b/GormCore/GormDocument.h @@ -213,26 +213,19 @@ /* Language translation */ /** - * Load a given file into the reciever using `filename`. + * Load a given file into the reciever using `filename'. */ - (void) importStringsFromFile: (NSString *)filename; -/** - * This method is used to translate all of the strings in the file from one language - * into another. This is helpful when attempting to translate an application for use - * in different locales. - */ -- (void) translate: (id)sender; - /** * Export the strings from receiver to the file indicated by 'filename'. */ - (void) exportStringsToFile: (NSString *)filename; /** - * Bring up a save panel to export the strings from the receiver. + * Import XLIFF document into the reciever using filename. */ -- (void) exportStrings: (id)sender; +- (BOOL) importXLIFFDocumentWithName: (NSString *)filename; /** * Exports XLIFF file for CAT. This method starts the process and calls diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index d7d5b33d..5bdb77fb 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -3187,68 +3187,6 @@ static void _real_close(GormDocument *self, } } -/** - * This method is used to translate all of the strings in the file from one language - * into another. This is helpful when attempting to translate an application for use - * in different locales. - */ -- (void) translate: (id)sender -{ - NSArray *fileTypes = [NSArray arrayWithObjects: @"strings", nil]; - NSOpenPanel *oPanel = [NSOpenPanel openPanel]; - int result; - - [oPanel setAllowsMultipleSelection: NO]; - [oPanel setCanChooseFiles: YES]; - [oPanel setCanChooseDirectories: NO]; - result = [oPanel runModalForDirectory: nil - file: nil - types: fileTypes]; - if (result == NSOKButton) - { - NSMutableArray *allObjects = [self _collectAllObjects]; - NSString *filename = [oPanel filename]; - NSEnumerator *en = nil; - id obj = nil; - - NS_DURING - { - [self importStringsFromFile: filename]; - } - NS_HANDLER - { - NSString *message = [localException reason]; - NSRunAlertPanel(_(@"Problem loading strings"), - message, nil, nil, nil); - } - NS_ENDHANDLER; - - [self touch]; // mark the document as modified... - - // change to translated values. - en = [allObjects objectEnumerator]; - while((obj = [en nextObject]) != nil) - { - if([obj isKindOfClass: [NSView class]]) - { - [obj setNeedsDisplay: YES]; - } - - // redisplay/flush, if the object is a window. - if([obj isKindOfClass: [NSWindow class]]) - { - NSWindow *w = (NSWindow *)obj; - [w setViewsNeedDisplay: YES]; - [w disableFlushWindow]; - [[w contentView] setNeedsDisplay: YES]; - [[w contentView] displayIfNeeded]; - [w enableFlushWindow]; - [w flushWindowIfNeeded]; - } - } - } -} - - (void) exportStringsToFile: (NSString *)filename { NSMutableArray *allObjects = [self _collectAllObjects]; @@ -3296,27 +3234,6 @@ static void _real_close(GormDocument *self, } } -/** - * This method is used to export all strings in a document to a file for Language - * translation. This allows the user to see all of the strings which can be translated - * and allows the user to provide a translateion for each of them. - */ -- (void) exportStrings: (id)sender -{ - NSSavePanel *sp = [NSSavePanel savePanel]; - int result; - - [sp setRequiredFileType: @"strings"]; - [sp setTitle: _(@"Save strings file as...")]; - result = [sp runModalForDirectory: NSHomeDirectory() - file: nil]; - if (result == NSOKButton) - { - NSString *filename = [sp filename]; - [self exportStringsToFile: filename]; - } -} - - (void) _collectObjectsFromObject: (id)obj withNode: (NSXMLElement *)node { @@ -3530,6 +3447,14 @@ static void _real_close(GormDocument *self, return result; } +/** + * Import XLIFF Document withthe name filename + */ +- (BOOL) importXLIFFDocumentWithName: (NSString *)filename +{ + return NO; +} + /** * Arrange views in front or in back of one another. */