0

Inside my Fragment I fetch a string which returns French translation but I want it to return English translation. What I noticed so far:

binding.textView = resources.getString(R.string.displayText) // returns French translation
binding.textView = getString(R.string.displayText) // returns English text

The issue seems to be when I use resources. I don't understand how and why this happens, both examples will call public String getString(int resId) inside Resources.

How can one return French text and the other one return English when both call the same getString() function?

I've tried using StringResources but that class is deprecated and shouldn't be used anymore.

Targetbus12
  • 75
  • 1
  • 5

1 Answers1

0

Every Resources has independent Configuration, and the Configuration's local determines the Resources's language. You can print your resources.getConfiguration().getLocales() to check its local. Maybe its Configuration was modified or the resources belongs to another context.

The default implemention of getString() is getResources().getString(), it use the default context's Resources.

greenfeel
  • 36
  • 1