0

Trying to localize the value from a variable.

String x = "greeting";

English:

<string name="greeting">Good morning</string>

Spanish:

<string name="greeting">Buenos dias</string>

I know it can be done statically like this:

getString(R.string.greeting);

But then I'm hardcoding 'greeting' where it should come from the value of the variable.

yoeriboven
  • 3,541
  • 3
  • 25
  • 40

1 Answers1

0

you need to create a new strings.xml file which will be localized as per the language you need. For this do the following:

  1. Right click on values --> new --> Value resource file
  2. File name --> strings.xml
  3. In available qualifier --> Locale
  4. Then select the language.

You will then get 2 separate strings file which you can write your translations

Rahul Agrawal
  • 521
  • 6
  • 24