Skip to content

Commit

Permalink
Adding a translation file, now ZFLangFile is a container for the tran…
Browse files Browse the repository at this point in the history
…slations and the real file
  • Loading branch information
cescofry committed Jun 28, 2013
1 parent 6c127fc commit 592e7e3
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 257 deletions.
14 changes: 12 additions & 2 deletions HiperStrings/Controllers/ZFExportFilesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

#import "ZFExportFilesController.h"
#import "ZFLangFile.h"
#import "ZFTranslationFile.h"
#import "ZFFileExportCell.h"
#import "ZFStringsConverter.h"

@implementation ZFExportFilesController

Expand All @@ -20,6 +21,15 @@ - (void)setScanner:(ZFStringScanner *)scanner {
#pragma mark - actions

- (IBAction)exportAction:(id)sender {

ZFStringsConverter *converter = [[ZFStringsConverter alloc] init];
[self.scanner.files enumerateObjectsUsingBlock:^(ZFTranslationFile *langFile, NSUInteger idx, BOOL *stop) {

}];




[self.window close];
}

Expand All @@ -35,7 +45,7 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
}

- (id)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
ZFLangFile *langFile = [self.scanner.files objectAtIndex:row];
ZFTranslationFile *langFile = [self.scanner.files objectAtIndex:row];
ZFFileExportCell *cell = [tableView makeViewWithIdentifier:@"langExportCell" owner:self];
[cell setLangFile:langFile];

Expand Down
4 changes: 2 additions & 2 deletions HiperStrings/Controllers/ZFFileDetailController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
//

#import <Foundation/Foundation.h>
#import "ZFLangFile.h"
#import "ZFTranslationFile.h"

@interface ZFFileDetailController : NSObject <NSTableViewDataSource, NSTableViewDelegate>

@property (nonatomic, strong) IBOutlet NSSegmentedControl *segmentedControl;
@property (nonatomic, strong) IBOutlet NSTableView *tableView;
@property (nonatomic, strong) ZFLangFile *langFile;
@property (nonatomic, strong) ZFTranslationFile *langFile;

- (IBAction)didSwithSegmentedControl:(NSSegmentedControl *)sender;

Expand Down
14 changes: 10 additions & 4 deletions HiperStrings/Controllers/ZFFileDetailController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
@interface ZFFileDetailController ()

@property (nonatomic, strong) NSArray *keys;
@property (nonatomic, strong) NSDictionary *rows;
@property (nonatomic, strong) NSArray *rows;
@property (nonatomic, strong) NSArray *columns;

@end

@implementation ZFFileDetailController

- (void)setLangFile:(ZFLangFile *)langFile {
- (void)setLangFile:(ZFTranslationFile *)langFile {
_langFile = langFile;

self.columns = [[NSArray arrayWithObject:KEY_KEY] arrayByAddingObjectsFromArray:[_langFile allLanguages]];
Expand Down Expand Up @@ -53,7 +53,7 @@ - (void)setLangFile:(ZFLangFile *)langFile {
#pragma mark - Segmented Controller

- (IBAction)didSwithSegmentedControl:(NSSegmentedControl *)sender {
self.rows = (self.segmentedControl.selectedSegment == 0)? [self.langFile iOStranslations] : [self.langFile androidTranslations];
self.rows = [self.langFile translationsByType:(self.segmentedControl.selectedSegment == 0)? ZFLangTypeIOS : ZFLangTypeAndorid andLanguageIdentifier:nil];
[self.tableView reloadData];
}

Expand All @@ -65,7 +65,13 @@ - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
if ([tableColumn.identifier isEqualToString:KEY_KEY]) return [self.keys objectAtIndex:row];
else return [[self.rows objectForKey:tableColumn.identifier] objectForKey:[self.keys objectAtIndex:row]];
else {
NSArray *translation = [self.langFile translationsByType:(self.segmentedControl.selectedSegment == 0)? ZFLangTypeIOS : ZFLangTypeAndorid andLanguageIdentifier:tableColumn.identifier];
ZFLangFile *lang = [translation lastObject];
return [lang.translations objectForKey:[self.keys objectAtIndex:row]];
}

//return [[self.rows objectForKey:tableColumn.identifier] objectForKey:[self.keys objectAtIndex:row]];
}

@end
2 changes: 1 addition & 1 deletion HiperStrings/Controllers/ZFFilesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "ZFFileDetailController.h"
#import "ZFExportFilesController.h"

@interface ZFFilesController : NSObject <NSTableViewDataSource, NSTableViewDelegate>
@interface ZFFilesController : NSObject <NSTableViewDataSource, NSTableViewDelegate, NSWindowDelegate>

@property (nonatomic, strong) IBOutlet ZFFileDetailController *fileDetailController;
@property (nonatomic, strong) IBOutlet NSTableView *filesTable;
Expand Down
35 changes: 9 additions & 26 deletions HiperStrings/Controllers/ZFFilesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "ZFFilesController.h"
#import "ZFFileViewCell.h"
#import "ZFStringScanner.h"
#import "ZFLangFile.h"
#import "ZFTranslationFile.h"

@interface ZFFilesController ()

Expand Down Expand Up @@ -61,31 +61,6 @@ - (IBAction)exportAction:(id)sender {
contextInfo:nil];
}

- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
/*
NSEnumerator *enumerator;
NSNumber *index;
NSMutableArray *tempArray;
id tempObject;
if ( returnCode == NSAlertDefaultReturn ) {
enumerator = [tableView selectedRowEnumerator];
tempArray = [NSMutableArray array];
while ( (index = [enumerator nextObject]) ) {
tempObject = [records objectAtIndex:[index intValue]];
[tempArray addObject:tempObject];
}
[records removeObjectsInArray:tempArray];
[tableView reloadData];
[self saveData];
}
*/
}


- (void)setURLFromDialog:(void (^)(BOOL success)) completed {
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:NO];
Expand All @@ -107,6 +82,8 @@ - (void)setURLFromDialog:(void (^)(BOOL success)) completed {
else [openDlg beginSheetModalForWindow:self.window completionHandler:completitionBlock];
}

#pragma mark - NSTableViewDelegate

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [self.scanner.files count];
}
Expand All @@ -123,4 +100,10 @@ - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
return YES;
}

#pragma mark NSWindowDelegate

- (void)windowWillClose:(NSNotification *)notification {
NSWindow *window = [notification object];
}

@end
53 changes: 39 additions & 14 deletions HiperStrings/Views/ZFFileExportCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#import "ZFFileExportCell.h"

#define I_TO_DROID @"i >> A"
#define DROID_TO_I @"A >> i"
#define SKIP @"X"

@interface ZFFileExportCell ()

@property (nonatomic, strong) NSButton *button;
Expand All @@ -34,27 +38,48 @@ - (void)awakeFromNib {
[self addSubview:self.button];
}

- (void)setLangFile:(ZFLangFile *)langFile {
- (void)setLangFile:(ZFTranslationFile *)langFile {
[super setLangFile:langFile];
[self.button setTitle:[self stringFromConversionDriver:self.langFile.conversionDriver]];
}

- (NSString *)stringFromConversionDriver:(ZFTranslationFileConversionDriver)driver {
NSString *conversionS = nil;

NSString *btnTxt = (langFile.iOSName)? @"i" : @"A";
[self.button setStringValue:btnTxt];
switch (driver) {
case ZFTranslationFileConversionDriverIOS:
conversionS = I_TO_DROID;
break;
case ZFTranslationFileConversionDriverAndorid:
conversionS = DROID_TO_I;
break;
case ZFTranslationFileConversionDriverSkip:
default:
conversionS = SKIP;
break;
}
return conversionS;
}

- (void)btnAction:(NSButton *)sender {
NSString *btnTxt = sender.stringValue;
if ([btnTxt isEqualToString:@"i"]) {
if (self.langFile.androidName) btnTxt = @"A";
else btnTxt = @"X";
}
if ([btnTxt isEqualToString:@"A"]) {
btnTxt = @"X";
ZFTranslationFileConversionDriver newDriver;
switch (self.langFile.conversionDriver) {
case ZFTranslationFileConversionDriverIOS:
newDriver = (self.langFile.androidName)? ZFTranslationFileConversionDriverAndorid : ZFTranslationFileConversionDriverSkip;
break;
case ZFTranslationFileConversionDriverAndorid:
newDriver = ZFTranslationFileConversionDriverSkip;
break;
case ZFTranslationFileConversionDriverSkip:
newDriver = (self.langFile.iOSName)? ZFTranslationFileConversionDriverIOS : ZFTranslationFileConversionDriverAndorid;
break;
default:
break;
}

if ([btnTxt isEqualToString:@"X"]) {
if (self.langFile.iOSName) btnTxt = @"i";
else btnTxt = @"A";
}

self.langFile.conversionDriver = newDriver;
[self.button setTitle:[self stringFromConversionDriver:self.langFile.conversionDriver]];
}

@end
4 changes: 2 additions & 2 deletions HiperStrings/Views/ZFFileViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
//

#import <Cocoa/Cocoa.h>
#import "ZFLangFile.h"
#import "ZFTranslationFile.h"

@interface ZFFileViewCell : NSTableCellView

@property (nonatomic, strong) ZFLangFile *langFile;
@property (nonatomic, strong) ZFTranslationFile *langFile;
@property (nonatomic, strong) NSTextField *titleLbl;
@property (nonatomic, strong) NSTextField *detailLbl;

Expand Down
2 changes: 1 addition & 1 deletion HiperStrings/Views/ZFFileViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (void)awakeFromNib {
}


- (void)setLangFile:(ZFLangFile *)langFile {
- (void)setLangFile:(ZFTranslationFile *)langFile {
_langFile = langFile;
if (_langFile.iOSName.length > 0) [self.titleLbl setStringValue:_langFile.iOSName];
if (_langFile.androidName.length > 0) [self.detailLbl setStringValue:_langFile.androidName];
Expand Down
2 changes: 1 addition & 1 deletion HiperStrings/ZFAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import "ZFAppDelegate.h"
#import "ZFStringScanner.h"
#import "ZFLangFile.h"
#import "ZFTranslationFile.h"

@interface ZFAppDelegate ()

Expand Down
28 changes: 18 additions & 10 deletions Strings.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1323015F177DD7DD008EB3D5 /* ZFLangFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 1371BBDD177DBDD9008EB467 /* ZFLangFile.m */; };
134E98D617799C4400D7D54B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 134E98D517799C4400D7D54B /* Foundation.framework */; };
134E98D917799C4400D7D54B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 134E98D817799C4400D7D54B /* main.m */; };
134E98DD17799C4400D7D54B /* Strings.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 134E98DC17799C4400D7D54B /* Strings.1 */; };
Expand Down Expand Up @@ -36,9 +37,10 @@
1371BBD5177B5954008EB467 /* icon.iconset in Resources */ = {isa = PBXBuildFile; fileRef = 1371BBD4177B5954008EB467 /* icon.iconset */; };
1371BBD8177D8E63008EB467 /* ZFExportFilesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1371BBD7177D8E63008EB467 /* ZFExportFilesController.m */; };
1371BBDB177D90DD008EB467 /* ZFFileExportCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 1371BBDA177D90DD008EB467 /* ZFFileExportCell.m */; };
13B17AED177AFB6000C0473E /* ZFLangFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFLangFile.m */; };
13B17AEE177AFE2800C0473E /* ZFLangFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFLangFile.m */; };
13B17AEF177AFE2800C0473E /* ZFLangFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFLangFile.m */; };
1371BBDE177DBDD9008EB467 /* ZFLangFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 1371BBDD177DBDD9008EB467 /* ZFLangFile.m */; };
13B17AED177AFB6000C0473E /* ZFTranslationFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFTranslationFile.m */; };
13B17AEE177AFE2800C0473E /* ZFTranslationFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFTranslationFile.m */; };
13B17AEF177AFE2800C0473E /* ZFTranslationFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AEC177AFB6000C0473E /* ZFTranslationFile.m */; };
13B17AF2177B02F700C0473E /* ZFUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AF1177B02F700C0473E /* ZFUtils.m */; };
13B17AF3177B051C00C0473E /* ZFUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AF1177B02F700C0473E /* ZFUtils.m */; };
13B17AF4177B052100C0473E /* ZFUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B17AF1177B02F700C0473E /* ZFUtils.m */; };
Expand Down Expand Up @@ -105,8 +107,10 @@
1371BBD7177D8E63008EB467 /* ZFExportFilesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ZFExportFilesController.m; path = Controllers/ZFExportFilesController.m; sourceTree = "<group>"; };
1371BBD9177D90DD008EB467 /* ZFFileExportCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZFFileExportCell.h; path = Views/ZFFileExportCell.h; sourceTree = "<group>"; };
1371BBDA177D90DD008EB467 /* ZFFileExportCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ZFFileExportCell.m; path = Views/ZFFileExportCell.m; sourceTree = "<group>"; };
13B17AEB177AFB6000C0473E /* ZFLangFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFLangFile.h; sourceTree = "<group>"; };
13B17AEC177AFB6000C0473E /* ZFLangFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFLangFile.m; sourceTree = "<group>"; };
1371BBDC177DBDD9008EB467 /* ZFLangFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFLangFile.h; sourceTree = "<group>"; };
1371BBDD177DBDD9008EB467 /* ZFLangFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFLangFile.m; sourceTree = "<group>"; };
13B17AEB177AFB6000C0473E /* ZFTranslationFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFTranslationFile.h; sourceTree = "<group>"; };
13B17AEC177AFB6000C0473E /* ZFTranslationFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFTranslationFile.m; sourceTree = "<group>"; };
13B17AF0177B02F700C0473E /* ZFUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZFUtils.h; sourceTree = "<group>"; };
13B17AF1177B02F700C0473E /* ZFUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZFUtils.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -198,10 +202,12 @@
134E98E717799DC900D7D54B /* ZFStringsConverter.m */,
134E990A1779A80700D7D54B /* ZFStringScanner.h */,
134E990B1779A80700D7D54B /* ZFStringScanner.m */,
13B17AEB177AFB6000C0473E /* ZFLangFile.h */,
13B17AEC177AFB6000C0473E /* ZFLangFile.m */,
13B17AEB177AFB6000C0473E /* ZFTranslationFile.h */,
13B17AEC177AFB6000C0473E /* ZFTranslationFile.m */,
13B17AF0177B02F700C0473E /* ZFUtils.h */,
13B17AF1177B02F700C0473E /* ZFUtils.m */,
1371BBDC177DBDD9008EB467 /* ZFLangFile.h */,
1371BBDD177DBDD9008EB467 /* ZFLangFile.m */,
);
name = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -425,8 +431,9 @@
134E98D917799C4400D7D54B /* main.m in Sources */,
134E98E917799DC900D7D54B /* ZFStringsConverter.m in Sources */,
134E990C1779A80700D7D54B /* ZFStringScanner.m in Sources */,
13B17AED177AFB6000C0473E /* ZFLangFile.m in Sources */,
13B17AED177AFB6000C0473E /* ZFTranslationFile.m in Sources */,
13B17AF2177B02F700C0473E /* ZFUtils.m in Sources */,
1371BBDE177DBDD9008EB467 /* ZFLangFile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -438,14 +445,15 @@
134E99031779A73900D7D54B /* ZFAppDelegate.m in Sources */,
134E990D1779AAD800D7D54B /* ZFStringsConverter.m in Sources */,
134E990E1779AADA00D7D54B /* ZFStringScanner.m in Sources */,
13B17AEE177AFE2800C0473E /* ZFLangFile.m in Sources */,
13B17AEE177AFE2800C0473E /* ZFTranslationFile.m in Sources */,
13B17AF3177B051C00C0473E /* ZFUtils.m in Sources */,
1371BBC1177B23A5008EB467 /* ZFFilesController.m in Sources */,
1371BBC6177B2410008EB467 /* ZFFileViewCell.m in Sources */,
1371BBC9177B29D2008EB467 /* ZFFileDetailController.m in Sources */,
1371BBCC177B2C1A008EB467 /* ZFTranslationView.m in Sources */,
1371BBD8177D8E63008EB467 /* ZFExportFilesController.m in Sources */,
1371BBDB177D90DD008EB467 /* ZFFileExportCell.m in Sources */,
1323015F177DD7DD008EB3D5 /* ZFLangFile.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -456,7 +464,7 @@
134E99221779E11C00D7D54B /* StringsTests.m in Sources */,
134E992B1779E16500D7D54B /* ZFStringConverterTests.m in Sources */,
134E992C1779E6B300D7D54B /* ZFStringsConverter.m in Sources */,
13B17AEF177AFE2800C0473E /* ZFLangFile.m in Sources */,
13B17AEF177AFE2800C0473E /* ZFTranslationFile.m in Sources */,
13B17AF4177B052100C0473E /* ZFUtils.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
28 changes: 13 additions & 15 deletions Strings/ZFLangFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
// ZFLangFile.h
// Strings
//
// Created by Francesco on 26/06/2013.
//
// Open Source Initiative OSI - The MIT License (MIT):Licensing [OSI Approved License] The MIT License (MIT)
// Copyright (c) 2013 ziofritz.
// Created by Francesco on 28/06/2013.
// Copyright (c) 2013 ziofritz. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface ZFLangFile : NSObject

@property (nonatomic, strong) NSString *iOSName;
@property (nonatomic, strong) NSString *androidName;
typedef enum {
ZFLangTypeIOS,
ZFLangTypeAndorid
} ZFLangType;

@property (nonatomic, strong) NSMutableDictionary *iOStranslations;
@property (nonatomic, strong) NSMutableDictionary *androidTranslations;
@interface ZFLangFile : NSObject

@property (nonatomic, strong) NSArray *allKeys;
@property (nonatomic, strong) NSArray *allLanguages;
@property (nonatomic, strong, readonly) NSURL *url;
@property (nonatomic, strong, readonly) NSString *fileName;
@property (nonatomic, assign, readonly) ZFLangType type;
@property (nonatomic, strong, readonly) NSString *language;
@property (nonatomic, strong, readonly) NSMutableDictionary *translations;

- (BOOL)addFileAtURL:(NSURL *) url;
- (BOOL)mergeWithFile:(ZFLangFile *)file;
- (void)finalizeMerge;
- (id)initWithURL:(NSURL *)url;

@end
Loading

0 comments on commit 592e7e3

Please sign in to comment.