Skip to content

Commit

Permalink
DTLocalizableStringTable: Added 'writeAsStringEncoding:error:entryWri…
Browse files Browse the repository at this point in the history
…teCallback:' method
  • Loading branch information
adeca committed Jul 27, 2012
1 parent ace9543 commit a6ae102
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions Core/Source/DTLocalizableStringTable.h
Expand Up @@ -21,6 +21,7 @@ typedef void(^DTLocalizableStringEntryWriteCallback)(DTLocalizableStringEntry *)

- (void)addEntry:(DTLocalizableStringEntry *)entry;

- (NSString*)writeAsStringEncoding:(NSStringEncoding)encoding error:(NSError **)error entryWriteCallback:(DTLocalizableStringEntryWriteCallback)entryWriteCallback;
- (BOOL)writeToFolderAtURL:(NSURL *)url encoding:(NSStringEncoding)encoding error:(NSError **)error entryWriteCallback:(DTLocalizableStringEntryWriteCallback)entryWriteCallback;

@end
32 changes: 19 additions & 13 deletions Core/Source/DTLocalizableStringTable.m
Expand Up @@ -75,25 +75,14 @@ - (void)addEntry:(DTLocalizableStringEntry *)entry
[_entryIndexByKey setObject:entry forKey:entry.rawKey];
}

- (BOOL)writeToFolderAtURL:(NSURL *)url encoding:(NSStringEncoding)encoding error:(NSError **)error entryWriteCallback:(DTLocalizableStringEntryWriteCallback)entryWriteCallback;
- (NSString*)writeAsStringEncoding:(NSStringEncoding)encoding error:(NSError **)error entryWriteCallback:(DTLocalizableStringEntryWriteCallback)entryWriteCallback
{
NSString *fileName = [_name stringByAppendingPathExtension:@"strings"];
NSString *tablePath = [[url path] stringByAppendingPathComponent:fileName];
NSURL *tableURL = [NSURL fileURLWithPath:tablePath];

if (!tableURL)
{
// this must be junk
return NO;
}

NSArray *sortedEntries = [_entries sortedArrayUsingSelector:@selector(compare:)];
NSArray *sortedEntries = [_entries sortedArrayUsingSelector:@selector(compare:)];

NSMutableString *tmpString = [NSMutableString string];

for (DTLocalizableStringEntry *entry in sortedEntries)
{

NSString *key = [entry rawKey];
NSString *value = [entry rawValue];

Expand Down Expand Up @@ -138,6 +127,23 @@ - (BOOL)writeToFolderAtURL:(NSURL *)url encoding:(NSStringEncoding)encoding erro

[tmpString appendString:@"\n"];
}

return [NSString stringWithString:tmpString];
}

- (BOOL)writeToFolderAtURL:(NSURL *)url encoding:(NSStringEncoding)encoding error:(NSError **)error entryWriteCallback:(DTLocalizableStringEntryWriteCallback)entryWriteCallback;
{
NSString *fileName = [_name stringByAppendingPathExtension:@"strings"];
NSString *tablePath = [[url path] stringByAppendingPathComponent:fileName];
NSURL *tableURL = [NSURL fileURLWithPath:tablePath];

if (!tableURL)
{
// this must be junk
return NO;
}

NSString *tmpString = [self writeAsStringEncoding:encoding error:error entryWriteCallback:entryWriteCallback];

return [tmpString writeToURL:tableURL
atomically:YES
Expand Down

0 comments on commit a6ae102

Please sign in to comment.