1

I am trying to create multilangualge app and faced with a problem! I have a string in values\strings.xml translated in German language values-de\strings.xml. I am trying to compare user input with those strings. If my input is in English and device's language is also English, everything works fine, but if I switch device's language to German and input a string in English, contains() and equals() methods will return false. Is there a way to compare strings in different languages? Thanks in advance! Also, sorry for my English!

 if (mystring.contains(context.getResources().getString(R.string.testString))) {
        check = true;
    }


 if (mystring.equals(context.getResources().getString(R.string.testString))) {
        check = true;
    }

1 Answers1

2

In android when you call getResources() it will always get the resources of the default locale, to get one from other locales you must specify explicitly which locale you want to use, and you can find how to do it here :

https://stackoverflow.com/a/33629163/6171845

Community
  • 1
  • 1
Sofiane Daoud
  • 868
  • 9
  • 21