mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 19:51:00 +00:00
Add code to import XLIFF from the Gorm GUI
This commit is contained in:
parent
48ae7aee08
commit
4c31eb5bd3
4 changed files with 165 additions and 95 deletions
|
@ -85,7 +85,10 @@
|
||||||
- (IBAction) loadPalette: (id) sender;
|
- (IBAction) loadPalette: (id) sender;
|
||||||
|
|
||||||
// Translation
|
// Translation
|
||||||
|
- (IBAction) importXLIFFDocument: (id)sender;
|
||||||
- (IBAction) exportXLIFFDocument: (id)sender;
|
- (IBAction) exportXLIFFDocument: (id)sender;
|
||||||
|
- (IBAction) translate: (id)sender;
|
||||||
|
- (IBAction) exportStrings: (id)sender;
|
||||||
|
|
||||||
// Print
|
// Print
|
||||||
- (IBAction) print: (id)sender;
|
- (IBAction) print: (id)sender;
|
||||||
|
|
|
@ -33,6 +33,12 @@
|
||||||
#import "GormAppDelegate.h"
|
#import "GormAppDelegate.h"
|
||||||
#import "GormLanguageViewController.h"
|
#import "GormLanguageViewController.h"
|
||||||
|
|
||||||
|
@interface GormDocument (Private)
|
||||||
|
|
||||||
|
- (NSMutableArray *) _collectAllObjects;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation GormAppDelegate
|
@implementation GormAppDelegate
|
||||||
|
|
||||||
// App delegate...
|
// App delegate...
|
||||||
|
@ -572,7 +578,65 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translation
|
// 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];
|
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||||
NSBundle *bundle = [NSBundle bundleForClass: [GormLanguageViewController class]];
|
NSBundle *bundle = [NSBundle bundleForClass: [GormLanguageViewController class]];
|
||||||
|
@ -624,8 +688,93 @@
|
||||||
return filename;
|
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
|
- (IBAction) print: (id) sender
|
||||||
{
|
{
|
||||||
[[NSApp keyWindow] print: sender];
|
[[NSApp keyWindow] print: sender];
|
||||||
|
|
|
@ -213,26 +213,19 @@
|
||||||
|
|
||||||
/* Language translation */
|
/* Language translation */
|
||||||
/**
|
/**
|
||||||
* Load a given file into the reciever using `filename`.
|
* Load a given file into the reciever using `filename'.
|
||||||
*/
|
*/
|
||||||
- (void) importStringsFromFile: (NSString *)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'.
|
* Export the strings from receiver to the file indicated by 'filename'.
|
||||||
*/
|
*/
|
||||||
- (void) exportStringsToFile: (NSString *)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
|
* Exports XLIFF file for CAT. This method starts the process and calls
|
||||||
|
|
|
@ -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
|
- (void) exportStringsToFile: (NSString *)filename
|
||||||
{
|
{
|
||||||
NSMutableArray *allObjects = [self _collectAllObjects];
|
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
|
- (void) _collectObjectsFromObject: (id)obj
|
||||||
withNode: (NSXMLElement *)node
|
withNode: (NSXMLElement *)node
|
||||||
{
|
{
|
||||||
|
@ -3530,6 +3447,14 @@ static void _real_close(GormDocument *self,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import XLIFF Document withthe name filename
|
||||||
|
*/
|
||||||
|
- (BOOL) importXLIFFDocumentWithName: (NSString *)filename
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arrange views in front or in back of one another.
|
* Arrange views in front or in back of one another.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue