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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.