From a1245bdee94ed34766c82722873cf076c135f2e4 Mon Sep 17 00:00:00 2001 From: Han Lin Yap Date: Tue, 4 Sep 2012 22:43:54 +0200 Subject: [PATCH] Fix #26, make powersource states translatable --- Battery Time Remaining/AppDelegate.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Battery Time Remaining/AppDelegate.m b/Battery Time Remaining/AppDelegate.m index 80120c0..14a85e8 100644 --- a/Battery Time Remaining/AppDelegate.m +++ b/Battery Time Remaining/AppDelegate.m @@ -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]; @@ -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)