0

I have this method in a class (normal class not activity)

    public String getTitle(Context context) {
      Log.d(TAG, Locale.getDefault().toString() + ", " + context.getString(R.string.title));
    return context.getString(R.string.title);
  }

When I call this method from activity passing context (getApplicationContext()) the log prints (ar, Categories) I double checked strings in xml and there are english and arabic word so how come? locale is arabic and it returns english resource.

Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31

1 Answers1

0

Add a folder in res , named it values-ar . Create a string.xml file inside that folder . Put your title there as below .

  <string name="title">arbic word</string>

If your locale is set to arbic than You can get your resouce String using below code .

context.getResources().getString(R.string.title);
Piash Sarker
  • 466
  • 5
  • 21
  • 1
    This is what I did exactly and still return English resource only. And when I transfer it to activity it runs well – Ahmed Elmokadim Nov 15 '17 at 13:12
  • Did you set the locale programatically ? – Piash Sarker Nov 15 '17 at 13:14
  • Try to change the language from your phone setting and get back to your application. – Piash Sarker Nov 15 '17 at 13:16
  • For setting locale programatically - https://stackoverflow.com/questions/2900023/change-language-programmatically-in-android/43938564#43938564 For Getting your current locale languaage - https://stackoverflow.com/questions/4212320/get-the-current-language-in-device – Piash Sarker Nov 15 '17 at 13:20