1

I'm having problem to change a textfield input language source through codes !
All I want is to change the keyboard language to specific language when ever I enter a textfield.

I'm already searched here and just found some small guidance for Iphone but I'm working on OSx App.

Thank you guys helping me again !

EDIT:
well ! new approaches : If I change my system preferences to appropriate language then most of the problems solved ! Date formatter become true and if I use this code snippet I can achieve correct language name ( before I just got en):

NSLocale * locale = [NSLocale currentLocale];        
NSString * localLanguage = [locale objectForKey:NSLocaleLanguageCode] ;
NSLog (@"Language : %@", localLanguage);    

BUT, I want to change the keyboard input language without changing the whole system preference. In fact, I want to change the Text Input service language to other installed language ( I have 2 ) when I enter into a special textfield ! ( is it clear ? )

Prooshani
  • 534
  • 7
  • 20
  • I was looking for this for an iPhone app. Could you point me to the element you found? I will try to return the favor. Also, I was told that it's worth adding a report to Apple's Bug Reporter - radr. David – ICL1901 May 21 '11 at 07:12
  • 1
    @David DellMonte, Sorry my friend for my late answer, you can find your answer [here](http://stackoverflow.com/questions/6150576/change-ios-apps-language-on-the-fly). – Prooshani Jun 15 '11 at 05:46

1 Answers1

10

Well, I answered my own question AGAIN !

for whom that may visit this question :
to get reached the user's keyboard language Input sources you have to follow this instructions :

  1. TIS ( Text Input Service ) is related to Carbon framework. So, first of all you have to import carbon.h to your implementation file:

    #import <Carbon/Carbon.h>

  2. Add carbon framework to your framework resource. To do this you have to navigate to Mac OSx Application Target -> Linked Frameworks and Libraries -> add carbon frame work.

  3. to change the keyboard input source, you can use for example controlTextDidBeginEditing delegate to detect user's textfield selection.Then you can select the proper language from installed language sources. for example I have two language installed, en and fa so I have 2 keyboard layout in language bar. Then you can select the language by selecting it's index.

  4. to find your desired language index you can use this :
    NSArray *langs=[NSLocale preferredLanguages];
    langs included by languages that you can reached by it's indexes.

  5. Now, it's time to change text input source programmatically using this codes :
    NSArray*langsArray=(NSArray*)TISCreateInputSourceList(NULL,FALSE); //make a list of installed languages
    TISInputSourceRef faSource=(TISInputSourceRef)[langsArray objectAtIndex:1]; //my second language is farsi (persian)
    TISSelectInputSource(faSource); // now second language selected for keyboard input resource

Hope it helps you.

Prooshani
  • 534
  • 7
  • 20