wbk727
wbk727

Reputation: 8408

Change text view text based on phone language without using string resources

How can I change the text within my textview based on the language set on the device without using string resources? I don't want to use string resources. As an example could someone please tell me what code I can use if the device language is in French and whether or not I'd need to use else if or else for including other languages.

TextView txt = (TextView)v.findViewById(R.id.WCBank_textView1);
txt.setText(Html.fromHtml("<font color='#E32017'>Red apples,</font>" +
                "<font color='#FFD300'> yellow bananas,</font>" +
                "<font color='#00782A'> green grapes</font>"
));

Upvotes: 1

Views: 960

Answers (1)

Jan
Jan

Reputation: 2070

I still prefer string resources for i18n (not for the individual words, but for the whole expression). That said, you could try something like this:

if (Locale.getDefault().equals(Locale.FRENCH) || Locale.getDefault().equals(Locale.FRANCE)) {
    // do the french stuff...
    txt.setText(...);
} else if ...

Upvotes: 1

Related Questions