0

I have 7 strings in the project like this

strings.xml //This is the default
strings.xml (en)
strings.xml (ar)
strings.xml (es)
strings.xml (de)
strings.xml (it)
strings.xml (ru)

And I have JSON in server like this

[
  {
    "default": {
      "Message": "..."
    },
    "en": {
      "Message": "..."
    },
    "ar": {
      "Message": "..."
    },
    "es": {
      "Message": "..."
    },
    "de": {
      "Message": "..."
    },
    "it": {
      "Message": "..."
    },
    "ru": {
      "Message": "..."
    }
  }
]

I want to read the message according to device language but the problem is how to know if the strings.xml is the default file to show default message from JSON?

Taha Sami
  • 1,565
  • 1
  • 16
  • 43
  • try this link : https://stackoverflow.com/a/22632022/12543430 – D_K Nov 27 '21 at 10:57
  • @D_K I can get the message from JSON using this [method](https://developer.android.com/reference/java/util/Locale#getLanguage()) but how to know it is time to get the default message? Because that method will give me the language code only – Taha Sami Nov 27 '21 at 11:17

1 Answers1

1

You can use this method.

In summary, you declare in each strings.xml a string telling which one is currently being used.

cmak
  • 576
  • 1
  • 4
  • 15