Changeset 10988


Ignore:
Timestamp:
Jul 10, 2010, 2:31:05 AM (12 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r10979 r10988  
    334334        tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED,  [fDefaults boolForKey: @"RPCUseWhitelist"]);
    335335       
    336         #warning localize and make consistent
    337         tr_formatter_size_init(1024, "KB", "MB", "GB", "TB");
    338         tr_formatter_speed_init(1024, "KB/s", "MB/s", "GB/s", "TB/s");
    339         tr_formatter_mem_init(1024, "KB", "MB", "GB", "TB");
     336        tr_formatter_size_init(1024, [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
     337                                    [NSLocalizedString(@"MB", "File size - megabytes") UTF8String],
     338                                    [NSLocalizedString(@"GB", "File size - gigabytes") UTF8String],
     339                                    [NSLocalizedString(@"TB", "File size - terabytes") UTF8String]);
     340
     341        tr_formatter_speed_init(1024, [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
     342                                    [NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String],
     343                                    [NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String],
     344                                    [NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)") UTF8String]); //why not?
     345
     346        tr_formatter_mem_init(1024, [NSLocalizedString(@"KB", "Memory size - kilobytes") UTF8String],
     347                                    [NSLocalizedString(@"MB", "Memory size - megabytes") UTF8String],
     348                                    [NSLocalizedString(@"GB", "Memory size - gigabytes") UTF8String],
     349                                    [NSLocalizedString(@"TB", "Memory size - terabytes") UTF8String]);
    340350       
    341351        fLib = tr_sessionInit("macosx", configDir, YES, &settings);
  • trunk/macosx/NSStringAdditions.m

    r10832 r10988  
    2929#import "utils.h"
    3030
     31@interface NSString (Private)
     32
     33+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb;
     34
     35@end
     36
    3137@implementation NSString (NSStringAdditions)
    3238
     
    8187+ (NSString *) stringForSpeed: (CGFloat) speed
    8288{
    83     return [[self stringForSpeedAbbrev: speed] stringByAppendingString: NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")];
     89    return [self stringForSpeed: speed
     90                kb: NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)")
     91                mb: NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)")
     92                gb: NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)")];
    8493}
    8594
    8695+ (NSString *) stringForSpeedAbbrev: (CGFloat) speed
    8796{
    88     if (speed <= 999.95) //0.0 K to 999.9 K
    89         return [NSString localizedStringWithFormat: @"%.1f K", speed];
    90    
    91     speed /= 1024.0;
    92    
    93     if (speed <= 99.995) //0.98 M to 99.99 M
    94         return [NSString localizedStringWithFormat: @"%.2f M", speed];
    95     else if (speed <= 999.95) //100.0 M to 999.9 M
    96         return [NSString localizedStringWithFormat: @"%.1f M", speed];
    97     else //insane speeds
    98         return [NSString localizedStringWithFormat: @"%.2f G", (speed / 1024.0)];
     97    return [self stringForSpeed: speed kb: @"K" mb: @"M" gb: @"G"];
    9998}
    10099
     
    187186
    188187@end
     188
     189@implementation NSString (Private)
     190
     191+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb
     192{
     193    if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s
     194        return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb];
     195   
     196    speed /= 1024.0;
     197   
     198    if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s
     199        return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb];
     200    else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s
     201        return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb];
     202    else //insane speeds
     203        return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb];
     204}
     205
     206@end
Note: See TracChangeset for help on using the changeset viewer.