Does anybody knows, can I get the current input language and/or keyboard layout in iPhone application? Can I also get a notification when input language was changed?
+3
A:
From the Apple Reference Library - "Getting the Current Language and Locale":
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
Alex Reynolds
2009-09-12 11:18:15
`[NSLocale preferredLanguages]` is the official way to get the list of preferred labguages. But I think @Danya want's the name of the current keyboard layout. That's something else.
Nikolai Ruhe
2009-09-12 11:20:28
Exactly. I need to change the content of the view depending of the current input language. So, I need to have a way to get the current keyboard language as well as a notification when user pressed the keyboard button to change language.
Danya
2009-09-12 12:08:16
+1
A:
You can add an observer to the default notification center:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(inputModeDidChange:)
name:@"UIKeyboardCurrentInputModeDidChangeNotification"
object:nil];
This method prints the currently selected input language (like "en_US"
or "de_DE"
):
- (void)inputModeDidChange:(NSNotification*)notification
{
id obj = [notification object];
if ([obj respondsToSelector:@selector(inputModeLastUsedPreference)]) {
id mode = [obj performSelector:@selector(inputModeLastUsedPreference)];
NSLog(@"mode: %@", mode);
}
}
BUT: All the above is not documented and you should not use it in shipping code!
Nikolai Ruhe
2009-09-12 15:50:46
You might have gotten the neg because you're describing code that can't be shipped using the SDK.
Shaggy Frog
2009-09-17 06:03:02
Interesting, but not useful--if I indeed cannot use in "shipping" code.
bentford
2010-03-18 13:08:48
I still don’t get it... Three downvotes for some reverse-engineered information which clearly states it’s non-applicability for shipping apps. Downvoters, are you offended by the information in this answer?
Nikolai Ruhe
2010-03-19 11:27:22