Skip to content

Commit

Permalink
Fix #26, make powersource states translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
codler committed Sep 4, 2012
1 parent a0532db commit 78a51b4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Battery Time Remaining/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[psPercentMenu setTag:kBTRMenuPowerSourcePercent];
[psPercentMenu setEnabled:NO];

NSMenuItem *psStateMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Power source: Unknown", @"Powersource menuitem") action:nil keyEquivalent:@""];
NSMenuItem *psStateMenu = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Power source: %@", @"Powersource menuitem"), NSLocalizedString(@"Unknown", @"Powersource state")] action:nil keyEquivalent:@""];
[psStateMenu setTag:kBTRMenuPowerSourceState];
[psStateMenu setEnabled:NO];

Expand Down Expand Up @@ -205,7 +205,15 @@ - (void)updateStatusItem

self.currentPercent = (int)[currentBatteryCapacity doubleValue] / [maxBatteryCapacity doubleValue] * 100;

[self.statusItem.menu itemWithTag:kBTRMenuPowerSourceState].title = [NSString stringWithFormat:NSLocalizedString(@"Power source: %@", @"Powersource menuitem"), CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey))];
NSString *psState = CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey));

psState = ([psState isEqualToString:(NSString *)CFSTR(kIOPSBatteryPowerValue)]) ?
NSLocalizedString(@"Battery Power", @"Powersource state") :
([psState isEqualToString:(NSString *)CFSTR(kIOPSACPowerValue)]) ?
NSLocalizedString(@"AC Power", @"Powersource state") :
NSLocalizedString(@"Off Line", @"Powersource state");

[self.statusItem.menu itemWithTag:kBTRMenuPowerSourceState].title = [NSString stringWithFormat:NSLocalizedString(@"Power source: %@", @"Powersource menuitem"), psState];

// We're connected to an unlimited power source (AC adapter probably)
if (kIOPSTimeRemainingUnlimited == timeRemaining)
Expand Down

0 comments on commit 78a51b4

Please sign in to comment.