How to translate language using Bing Api on iOS?

I am new to iOS I am building an app that contains a language translation feature, so I am using the Bing API for it and FGTranslator from Github.

But it translates French to English, but I want to make a choice for the user, like how the user can select the language, like how French

, Spanish

etc., then how to convert the language from English to Spanish. FGTranslator Please give me a solution for this.

Here, FGTranslator

the language conversion method looks like

[self.translator translateText:@"Helo How are You"
               completion:^(NSError *error, NSString *translated, NSString *sourceLanguage)
{
     if (error)
     {
         [self showErrorWithError:error];

         [SVProgressHUD dismiss];
     }
     else
     {
         NSString *fromLanguage = [[self currentLocale] displayNameForKey:NSLocaleIdentifier value:sourceLanguage];
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:fromLanguage ? [NSString stringWithFormat:@"from %@", fromLanguage] : nil
                                                         message:translated
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil];
         [alert show];
         NSLog(@"STERING %@",translated);
         [SVProgressHUD dismiss];
     }
 }];

      

Here's how I can set another language from a custom choice.

Here I am writing a method for it, then I got an error like like FGTranslatorErrorDomainerror 1

. please help me I am writing a method like

[self.translator translateText:self.textView.text withSource:@"en" target:@"js" completion:^(NSError *error, NSString *translated, NSString *sourceLanguage) {

     if (error)
     {
         [self showErrorWithError:error];
         [SVProgressHUD dismiss];
     }
     else
     {
         NSLog(@"Translated Text %@",translated);
    }
 }];

      

Here I write en

for English and js

for Japanese Please help me.

+3


source to share


1 answer


You seem to be using the wrong name for the translation. The method supportedLanguages:

returns the language type English

, French

and so on, but you are using en

, and fr

to translate them.

So this should work:



[self.translator translateText:self.textView.text withSource:@"English" target:@"French" completion:^(NSError *error, NSString *translated, NSString *sourceLanguage) { /* ... */ }];

      

+1


source







All Articles