Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate String(Text) to Different Lagunage at Runtime in android

I have a string obtained from EditText.

String test= et.getText.toString();
test=" My name is john tokest";

After that I have spinner with different language like, English, Chinese, French, Hindi.

If I choose French, I want to display in text view in French translate test string.

like this: Mon nom est john tokest

Is it possible in android? or not?

Note: I have done this successfully if I have created value-fr folder in res and included respective string, but I want to do this at run time.

like image 903
Horrorgoogle Avatar asked Dec 05 '25 16:12

Horrorgoogle


1 Answers

Add google translation jar in your project. And then you can use it like this:

String test="My name is john tokest";
try {
        String translatedText = Translate.execute(test, Language.ENGLISH, Language.FRENCH);//You can pass params as per text input and desired output.
        System.out.println(translatedText)
    } catch (Exception e) {
        e.printStackTrace();
    }

Reference article

like image 115
MysticMagicϡ Avatar answered Dec 08 '25 04:12

MysticMagicϡ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!