when localizing units of speed, localize the full speed string; localize the speed & size strings passed to libtransmission

This commit is contained in:
Mitchell Livingston 2010-07-10 02:31:05 +00:00
parent 71cadc02b6
commit 5c66ff7c9a
2 changed files with 44 additions and 16 deletions

View File

@ -333,10 +333,20 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
tr_bencDictAddStr(&settings, TR_PREFS_KEY_RPC_USERNAME, [[fDefaults stringForKey: @"RPCUsername"] UTF8String]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, [fDefaults boolForKey: @"RPCUseWhitelist"]);
#warning localize and make consistent
tr_formatter_size_init(1024, "KB", "MB", "GB", "TB");
tr_formatter_speed_init(1024, "KB/s", "MB/s", "GB/s", "TB/s");
tr_formatter_mem_init(1024, "KB", "MB", "GB", "TB");
tr_formatter_size_init(1024, [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
[NSLocalizedString(@"MB", "File size - megabytes") UTF8String],
[NSLocalizedString(@"GB", "File size - gigabytes") UTF8String],
[NSLocalizedString(@"TB", "File size - terabytes") UTF8String]);
tr_formatter_speed_init(1024, [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
[NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String],
[NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String],
[NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)") UTF8String]); //why not?
tr_formatter_mem_init(1024, [NSLocalizedString(@"KB", "Memory size - kilobytes") UTF8String],
[NSLocalizedString(@"MB", "Memory size - megabytes") UTF8String],
[NSLocalizedString(@"GB", "Memory size - gigabytes") UTF8String],
[NSLocalizedString(@"TB", "Memory size - terabytes") UTF8String]);
fLib = tr_sessionInit("macosx", configDir, YES, &settings);
tr_bencFree(&settings);

View File

@ -28,6 +28,12 @@
#import <transmission.h>
#import "utils.h"
@interface NSString (Private)
+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb;
@end
@implementation NSString (NSStringAdditions)
+ (NSString *) ellipsis
@ -80,22 +86,15 @@
+ (NSString *) stringForSpeed: (CGFloat) speed
{
return [[self stringForSpeedAbbrev: speed] stringByAppendingString: NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")];
return [self stringForSpeed: speed
kb: NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)")
mb: NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)")
gb: NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)")];
}
+ (NSString *) stringForSpeedAbbrev: (CGFloat) speed
{
if (speed <= 999.95) //0.0 K to 999.9 K
return [NSString localizedStringWithFormat: @"%.1f K", speed];
speed /= 1024.0;
if (speed <= 99.995) //0.98 M to 99.99 M
return [NSString localizedStringWithFormat: @"%.2f M", speed];
else if (speed <= 999.95) //100.0 M to 999.9 M
return [NSString localizedStringWithFormat: @"%.1f M", speed];
else //insane speeds
return [NSString localizedStringWithFormat: @"%.2f G", (speed / 1024.0)];
return [self stringForSpeed: speed kb: @"K" mb: @"M" gb: @"G"];
}
+ (NSString *) stringForRatio: (CGFloat) ratio
@ -186,3 +185,22 @@
}
@end
@implementation NSString (Private)
+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb
{
if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb];
speed /= 1024.0;
if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s
return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb];
else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb];
else //insane speeds
return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb];
}
@end