Localization support. Change many names in NJKeyInputField to standard keyboard short...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 12 Mar 2013 11:45:20 +0000 (12:45 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 12 Mar 2013 11:45:20 +0000 (12:45 +0100)
13 files changed:
Categories/NSRunningApplication+NJPossibleNames.m
Classes/NJDeviceController.m
Classes/NJInputAnalog.m
Classes/NJInputButton.m
Classes/NJInputHat.m
Classes/NJKeyInputField.h
Classes/NJKeyInputField.m
Classes/NJMapping.m
Classes/NJMappingMenuController.m
Classes/NJMappingsController.m
Enjoyable.xcodeproj/project.pbxproj
Info.plist
Resources/English.lproj/Localizable.strings [new file with mode: 0644]

index a3fdaf581111c6501611033c07ce2c5db6c1436f..895134cb9aef5319c700ba983093d34e467a1b77 100644 (file)
         return self.localizedName;
     else if (self.bundleIdentifier)
         return self.bundleIdentifier;
-    else
-        return @"@Application";
+    else {
+        return NSLocalizedString(@"@Application",
+                                 @"Magic string to trigger automatic "
+                                 @"mapping renames. It should look like "
+                                 @"an identifier rather than normal "
+                                 @"word, with the @ on the front.");
+    }
 }
 
 @end
index 2849838b22e2c576de28e45d06add5f278075776..2ce3fa93c8f72bb2f6acb4f32b71d9540f5bc76e 100644 (file)
@@ -202,13 +202,13 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD
     IOHIDManagerSetDeviceMatchingMultiple(_hidManager, (__bridge CFArrayRef)criteria);
     IOReturn ret = IOHIDManagerOpen(_hidManager, kIOHIDOptionsTypeNone);
     if (ret != kIOReturnSuccess) {
-        [[NSAlert alertWithMessageText:@"Input devices are unavailable"
+        [[NSAlert alertWithMessageText:NSLocalizedString(@"input devices unavailable",
+                                                         @"error title when devices can't be read")
                          defaultButton:nil
                        alternateButton:nil
                            otherButton:nil
-             informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. "
-                                       @"Input may not be correctly detected or mapped.",
-                                       ret]
+             informativeTextWithFormat:NSLocalizedString(@"input error 0x%08x occurred",
+                                                         @"message containing IOReturn failure code when devices can't be read"), ret]
             beginSheetModalForWindow:outlineView.window
             modalDelegate:nil
             didEndSelector:nil
index 7b4b15a831c4d0fcfde586972e79560ceb5e93c7..41a39f276d41eca6e093a63be57a456afd16205f 100644 (file)
@@ -21,9 +21,9 @@ static float normalize(long p, long min, long max) {
 
 - (id)initWithIndex:(int)index rawMin:(long)rawMin_ rawMax:(long)rawMax_ {
     if ((self = [super init])) {
-        self.name = [[NSString alloc] initWithFormat: @"Axis %d", index];
-        self.children = @[[[NJInput alloc] initWithName:@"Low" base:self],
-                          [[NJInput alloc] initWithName:@"High" base:self]];
+        self.name = [[NSString alloc] initWithFormat:NSLocalizedString(@"axis %d", @"axis name"), index];
+        self.children = @[[[NJInput alloc] initWithName:NSLocalizedString(@"axis low", @"axis low trigger") base:self],
+                          [[NJInput alloc] initWithName:NSLocalizedString(@"axis high", @"axis high trigger") base:self]];
         rawMax = rawMax_;
         rawMin = rawMin_;
     }
index 0c3b0ce32de0105413d0d1c4e68c86be853e62b7..caa4d8e55c54ba1824ecd957228defab821f5c3d 100644 (file)
 - (id)initWithName:(NSString *)name idx:(int)idx max:(long)max {
     if ((self = [super init])) {
         _max = max;
+        self.name = [NSString stringWithFormat:NSLocalizedString(@"button %d", @"button name"), idx];
+        
         if (name.length)
-            self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name];
-        else
-            self.name = [NSString stringWithFormat:@"Button %d", idx];
+            self.name = [self.name stringByAppendingFormat:@"- %@", name];
     }
     return self;
 }
index e0e127fec646b6d4b15e51b144cede49ede7c0b2..d267b716e7ae652cd7dfaae63cee8507e3dfc0ab 100644 (file)
@@ -31,11 +31,11 @@ static BOOL active_fourway[20] = {
 
 - (id)initWithIndex:(int)index {
     if ((self = [super init])) {
-        self.children = @[[[NJInput alloc] initWithName:@"Up" base:self],
-                          [[NJInput alloc] initWithName:@"Down" base:self],
-                          [[NJInput alloc] initWithName:@"Left" base:self],
-                          [[NJInput alloc] initWithName:@"Right" base:self]];
-        self.name = [NSString stringWithFormat:@"Hat Switch %d", index];
+        self.children = @[[[NJInput alloc] initWithName:NSLocalizedString(@"hat up", @"hat switch up state") base:self],
+                          [[NJInput alloc] initWithName:NSLocalizedString(@"hat down", @"hat switch down state") base:self],
+                          [[NJInput alloc] initWithName:NSLocalizedString(@"hat left", @"hat switch left state") base:self],
+                          [[NJInput alloc] initWithName:NSLocalizedString(@"hat right", @"hat switch right state") base:self]];
+        self.name = [NSString stringWithFormat:NSLocalizedString(@"hat switch %d", @"hat switch name"), index];
     }
     return self;
 }
index 9a7a3af9863cd3b86322ec8ea0cf856faf413b4e..84498ff9351f07fb96b8e056b31261ea236958b6 100644 (file)
@@ -7,7 +7,7 @@
 
 #import <Cocoa/Cocoa.h>
 
-extern CGKeyCode NJKeyInputFieldEmpty;
+extern const CGKeyCode NJKeyInputFieldEmpty;
 
 @protocol NJKeyInputFieldDelegate;
 
index f4525e5b2b0e3f7f3b25fc5c603b60373c957aa2..2073d8de7f162a011594581768a5c8d60b2120b6 100644 (file)
@@ -7,7 +7,7 @@
 
 #import "NJKeyInputField.h"
 
-CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
+const CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
 
 @implementation NJKeyInputField
 
@@ -33,7 +33,6 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
 
 + (NSString *)stringForKeyCode:(CGKeyCode)keyCode {
     switch (keyCode) {
-        case 0xffff: return @"";
         case 0x7a: return @"F1";
         case 0x78: return @"F2";
         case 0x63: return @"F3";
@@ -54,7 +53,7 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
         case 0x4f: return @"F18";
         case 0x50: return @"F19";
             
-        case 0x35: return @"Esc";
+        case 0x35: return @"";
         case 0x32: return @"`";
             
         case 0x12: return @"1";
@@ -71,26 +70,27 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
         case 0x18: return @"=";
             
         case 0x3f: return @"Fn";
-        case 0x36: return @"Right Command";
-        case 0x37: return @"Left Command";
-        case 0x38: return @"Left Shift";
-        case 0x39: return @"Caps Lock";
-        case 0x3a: return @"Left Option";
-        case 0x3b: return @"Left Control";
-        case 0x3c: return @"Right Shift";
-        case 0x3d: return @"Right Option";
-        case 0x3e: return @"Right Control";
+        case 0x36: return NSLocalizedString(@"Right ⌘", @"keyboard key");
+        case 0x37: return NSLocalizedString(@"Left ⌘", @"keyboard key");
+        case 0x38: return NSLocalizedString(@"Left ⇧", @"keyboard key");
+        case 0x39: return @"";
+        case 0x3a: return NSLocalizedString(@"Left ⌥", @"keyboard key");
+        case 0x3b: return NSLocalizedString(@"Left ⌃", @"keyboard key");
+        case 0x3c: return NSLocalizedString(@"Right ⇧", @"keyboard key");
+        case 0x3d: return NSLocalizedString(@"Right ⌃", @"keyboard key");
+        case 0x3e: return NSLocalizedString(@"Right ⌥", @"keyboard key");
             
-        case 0x73: return @"Home";
-        case 0x74: return @"Page Up";
-        case 0x75: return @"Delete";
-        case 0x77: return @"End";
-        case 0x79: return @"Page Down";
+        case 0x73: return @"↖";
+        case 0x74: return @"⇞";
+        case 0x77: return @"↘";
+        case 0x79: return @"⇟";
+
+        case 0x75: return @"⌦";
+        case 0x33: return @"⌫";
             
-        case 0x30: return @"Tab";
-        case 0x33: return @"Backspace";
-        case 0x24: return @"Return";
-        case 0x31: return @"Space";
+        case 0x30: return @"⇥";
+        case 0x24: return @"↩";
+        case 0x31: return @"␣";
             
         case 0x0c: return @"Q";
         case 0x0d: return @"W";
@@ -127,31 +127,35 @@ CGKeyCode NJKeyInputFieldEmpty = 0xFFFF;
         case 0x2f: return @".";
         case 0x2c: return @"/";
             
-        case 0x47: return @"Clear";
-        case 0x51: return @"Keypad =";
-        case 0x4b: return @"Keypad /";
-        case 0x43: return @"Keypad *";
-        case 0x59: return @"Keypad 7";
-        case 0x5b: return @"Keypad 8";
-        case 0x5c: return @"Keypad 9";
-        case 0x4e: return @"Keypad -";
-        case 0x56: return @"Keypad 4";
-        case 0x57: return @"Keypad 5";
-        case 0x58: return @"Keypad 6";
-        case 0x45: return @"Keypad +";
-        case 0x53: return @"Keypad 1";
-        case 0x54: return @"Keypad 2";
-        case 0x55: return @"Keypad 3";
-        case 0x52: return @"Keypad 0";
-        case 0x41: return @"Keypad .";
-        case 0x4c: return @"Enter";
+        case 0x47: return @"";
+        case 0x51: return NSLocalizedString(@"Key Pad =", @"numeric pad key");
+        case 0x4b: return NSLocalizedString(@"Key Pad /", @"numeric pad key");
+        case 0x43: return NSLocalizedString(@"Key Pad *", @"numeric pad key");
+        case 0x59: return NSLocalizedString(@"Key Pad 7", @"numeric pad key");
+        case 0x5b: return NSLocalizedString(@"Key Pad 8", @"numeric pad key");
+        case 0x5c: return NSLocalizedString(@"Key Pad 9", @"numeric pad key");
+        case 0x4e: return NSLocalizedString(@"Key Pad -", @"numeric pad key");
+        case 0x56: return NSLocalizedString(@"Key Pad 4", @"numeric pad key");
+        case 0x57: return NSLocalizedString(@"Key Pad 5", @"numeric pad key");
+        case 0x58: return NSLocalizedString(@"Key Pad 6", @"numeric pad key");
+        case 0x45: return NSLocalizedString(@"Key Pad +", @"numeric pad key");
+        case 0x53: return NSLocalizedString(@"Key Pad 1", @"numeric pad key");
+        case 0x54: return NSLocalizedString(@"Key Pad 2", @"numeric pad key");
+        case 0x55: return NSLocalizedString(@"Key Pad 3", @"numeric pad key");
+        case 0x52: return NSLocalizedString(@"Key Pad 0", @"numeric pad key");
+        case 0x41: return NSLocalizedString(@"Key Pad .", @"numeric pad key");
+        case 0x4c: return @"";
             
-        case 0x7e: return @"Up";
-        case 0x7d: return @"Down";
-        case 0x7b: return @"Left";
-        case 0x7c: return @"Right";
+        case 0x7e: return @"↑";
+        case 0x7d: return @"↓";
+        case 0x7b: return @"←";
+        case 0x7c: return @"→";
+        case 0xffff: // NJKeyInputFieldEmpty
+            return @"";
         default:
-            return [[NSString alloc] initWithFormat:@"Key 0x%x", keyCode];
+            return [[NSString alloc] initWithFormat:
+                    NSLocalizedString(@"key 0x%x", @"unknown key code"),
+                    keyCode];
     }
 }
 
index 355dbccdf58951959b52f630ad841665626ccea7..0e67cd3469e66f3f7e6b2072b6843aa8629238a0 100644 (file)
 // Extra checks during initialization because the data is often loaded
 // from untrusted serializations.
 
-- (id)initWithName:(NSString *)name {
+- (id)init {
     if ((self = [super init])) {
-        self.name = [name isKindOfClass:NSString.class] ? name : @"Untitled";
+        self.name = NSLocalizedString(@"Untitled", @"name for new mappings");
         _entries = [[NSMutableDictionary alloc] init];
     }
     return self;
 }
 
+- (id)initWithName:(NSString *)name {
+    if ((self = [self init])) {
+        if ([name isKindOfClass:NSString.class])
+            self.name = name;
+    }
+    return self;
+}
+
 - (id)initWithSerialization:(NSDictionary *)serialization
                    mappings:(NSArray *)mappings {
     if ((self = [self initWithName:serialization[@"name"]])) {
           && [serialization[@"entries"] isKindOfClass:NSDictionary.class])) {
         *error = [NSError errorWithDomain:@"Enjoyable"
                                      code:0
-                              description:@"This isn't a valid mapping file."];
+                              description:NSLocalizedString(@"invalid mapping file",
+                                                            @"error when imported file was JSON but not a mapping")];
         return nil;
     }
     
index 882a984405b2fc5865de6ee2cc45d067a05e2fb5..03ce31d278dd03dca154b0fccab326b399c00e0e 100644 (file)
@@ -76,7 +76,8 @@
         [self.menu insertItem:item atIndex:index++];
         if (added == MAXIMUM_MAPPINGS_IN_MENU
             && mappings.count > MAXIMUM_MAPPINGS_IN_MENU + 1) {
-            NSString *msg = [NSString stringWithFormat:@"(and %lu more…)",
+            NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"mapping overflow %lu",
+                                                                         @"menu item when mappings list overflows"),
                              mappings.count - MAXIMUM_MAPPINGS_IN_MENU];
             NSMenuItem *end = [[NSMenuItem alloc] initWithTitle:msg
                                                          action:@selector(_mappingListWasChosen:)
 }
 
 - (void)eventTranslationActivated:(NSNotification *)note {
-    self.eventTranslationToggle.title = @"Disable";
+    self.eventTranslationToggle.title = NSLocalizedString(@"Disable",
+                                                          @"menu item text to disable event translation");
 }
 
 - (void)eventTranslationDeactivated:(NSNotification *)note {
-    self.eventTranslationToggle.title = @"Enable";    
+    self.eventTranslationToggle.title = NSLocalizedString(@"Enable",
+                                                          @"menu item text to enable event translation");
 }
 
-
-
 @end
index 5faa4bf47d0384dac19695592aacf51335fa36c9..500e90150ed1277b30145530e4272f9fd496488f 100644 (file)
@@ -22,7 +22,8 @@
 - (id)init {
     if ((self = [super init])) {
         _mappings = [[NSMutableArray alloc] init];
-        _currentMapping = [[NJMapping alloc] initWithName:@"(default)"];
+        _currentMapping = [[NJMapping alloc] initWithName:
+                           NSLocalizedString(@"(default)", @"default name for first the mapping")];
         _manualMapping = _currentMapping;
         [_mappings addObject:_currentMapping];
     }
@@ -79,7 +80,9 @@
 
     if (!found) {
         [self activateMapping:oldMapping];
-        if ([oldMapping.name.lowercaseString isEqualToString:@"@application"]) {
+        if ([oldMapping.name.lowercaseString isEqualToString:@"@application"]
+            || [oldMapping.name.lowercaseString isEqualToString:
+                NSLocalizedString(@"@Application", nil).lowercaseString]) {
             oldMapping.name = app.bestMappingName;
             [self mappingsChanged];
         }
 }
 
 - (IBAction)addPressed:(id)sender {
-    NJMapping *newMapping = [[NJMapping alloc] initWithName:@"Untitled"];
+    NJMapping *newMapping = [[NJMapping alloc] init];
     [_mappings addObject:newMapping];
     [self activateMapping:newMapping];
     [self mappingsChanged];
         NJMapping *mergeInto = self[mapping.name];
         if ([mergeInto hasConflictWith:mapping]) {
             NSAlert *conflictAlert = [[NSAlert alloc] init];
-            conflictAlert.messageText = @"Replace existing mappings?";
+            conflictAlert.messageText = NSLocalizedString(@"import conflict prompt", @"Title of import conflict alert");
             conflictAlert.informativeText =
-            [NSString stringWithFormat:
-                @"This file contains inputs you've already mapped in \"%@\". Do you "
-                @"want to merge them and replace your existing mappings, or import this "
-                @"as a separate mapping?", mapping.name];
-            [conflictAlert addButtonWithTitle:@"Merge"];
-            [conflictAlert addButtonWithTitle:@"Cancel"];
-            [conflictAlert addButtonWithTitle:@"New Mapping"];
+            [NSString stringWithFormat:NSLocalizedString(@"import conflict in %@", @"Explanation of import conflict"),
+                                       mapping.name];
+            [conflictAlert addButtonWithTitle:NSLocalizedString(@"import and merge", @"button to merge imported mappings")];
+            [conflictAlert addButtonWithTitle:NSLocalizedString(@"cancel import", @"button to cancel import")];
+            [conflictAlert addButtonWithTitle:NSLocalizedString(@"import new mapping", @"button to import as new mapping")];
             [conflictAlert beginSheetModalForWindow:popoverActivate.window
                                       modalDelegate:self
                                      didEndSelector:@selector(mappingConflictDidResolve:returnCode:contextInfo:)
index 7b879c48d67a5c3a9d5a5a34370337b7b009181c..ef109f0c871f06fd1eeb7a4ce12b2b83a6ea459b 100644 (file)
@@ -9,6 +9,7 @@
 /* Begin PBXBuildFile section */
                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
                D594BF000FAE7397007A85F2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D594BEFF0FAE7397007A85F2 /* IOKit.framework */; };
+               EE1F3CEA16EF4182008C6426 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = EE1F3CE816EF4182008C6426 /* Localizable.strings */; };
                EE3D897A16EA7EFC00596D1F /* Status Menu Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = EE3D897916EA7EFC00596D1F /* Status Menu Icon@2x.png */; };
                EE3D897C16EA806E00596D1F /* Status Menu Icon Disabled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = EE3D897B16EA806E00596D1F /* Status Menu Icon Disabled@2x.png */; };
                EE3D897F16EA817E00596D1F /* Status Menu Icon Disabled.png in Resources */ = {isa = PBXBuildFile; fileRef = EE3D897D16EA817E00596D1F /* Status Menu Icon Disabled.png */; };
@@ -69,6 +70,7 @@
                8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
                8D1107320486CEB800E47090 /* Enjoyable.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Enjoyable.app; sourceTree = BUILT_PRODUCTS_DIR; };
                D594BEFF0FAE7397007A85F2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
+               EE1F3CE916EF4182008C6426 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = Resources/English.lproj/Localizable.strings; sourceTree = "<group>"; };
                EE3D897916EA7EFC00596D1F /* Status Menu Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Status Menu Icon@2x.png"; path = "Resources/Status Menu Icon@2x.png"; sourceTree = "<group>"; };
                EE3D897B16EA806E00596D1F /* Status Menu Icon Disabled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Status Menu Icon Disabled@2x.png"; path = "Resources/Status Menu Icon Disabled@2x.png"; sourceTree = "<group>"; };
                EE3D897D16EA817E00596D1F /* Status Menu Icon Disabled.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Status Menu Icon Disabled.png"; path = "Resources/Status Menu Icon Disabled.png"; sourceTree = "<group>"; };
                29B97317FDCFA39411CA2CEA /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               EE1F3CE816EF4182008C6426 /* Localizable.strings */,
                                EE3D897D16EA817E00596D1F /* Status Menu Icon Disabled.png */,
                                EE3D897E16EA817E00596D1F /* Status Menu Icon.png */,
                                EE3D897B16EA806E00596D1F /* Status Menu Icon Disabled@2x.png */,
                                EE3D897C16EA806E00596D1F /* Status Menu Icon Disabled@2x.png in Resources */,
                                EE3D897F16EA817E00596D1F /* Status Menu Icon Disabled.png in Resources */,
                                EE3D898016EA817E00596D1F /* Status Menu Icon.png in Resources */,
+                               EE1F3CEA16EF4182008C6426 /* Localizable.strings in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
 /* End PBXSourcesBuildPhase section */
 
 /* Begin PBXVariantGroup section */
+               EE1F3CE816EF4182008C6426 /* Localizable.strings */ = {
+                       isa = PBXVariantGroup;
+                       children = (
+                               EE1F3CE916EF4182008C6426 /* English */,
+                       );
+                       name = Localizable.strings;
+                       sourceTree = "<group>";
+               };
                EEF17D1B16E8E23A00D7DC4D /* InfoPlist.strings */ = {
                        isa = PBXVariantGroup;
                        children = (
index 1ce77583a0fecc4089aa0a81989dc235300383a2..7ca8cd379611b87cdcde8220d6c8401a3cb77bf3 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>175</string>
+       <string>182</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
diff --git a/Resources/English.lproj/Localizable.strings b/Resources/English.lproj/Localizable.strings
new file mode 100644 (file)
index 0000000..4a55926
Binary files /dev/null and b/Resources/English.lproj/Localizable.strings differ