2

I am trying to make a translation button for Romanian and I have tried to use RO, Romanian, ro-rRO and ro as code for Locale.RO, but none seem to work. I have added a Romanian string translation xml, but this doesn't help. I have seen in a previous post that Romanian should should be supported even on older versions. There is also an answer recommending this command for this:

public Locale (String language, String country)

However, I have no idea where to implement this and if it would work. Can anyone help me to fix this?

An extract of the code that gives me the error can be found below:

Configuration config = new Configuration();
                    config.locale = Locale.RO;
                    getResources().updateConfiguration(config, getResources().getDisplayMetrics());
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Physther
  • 246
  • 3
  • 10

1 Answers1

1
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.setLocale(new Locale("ro", "RO"));
res.updateConfiguration(conf, dm);

And translated strings should be placed in /res/values-ro/strings.xml, where ro is country code for Romanian translations. If you add a folder with /res/values-es/strings.xml, translations will be for Spain(es country code).

If all is correct, android studio should display something like this

enter image description here

Cătălin Florescu
  • 5,012
  • 1
  • 25
  • 36
  • Thank you, Catalin! The code works, but the text is still in English. Do I need to change something in the strings.xml file? Now I have it like this: *strings.xml (ro-rRo)* – Physther Jan 05 '18 at 14:09
  • Your translations should be placed in `/res/values-ro` with same name, `strings.xml`. Just a new folder for values with country code added. I updated my answer. – Cătălin Florescu Jan 05 '18 at 14:48
  • It doesn't show like that, but it makes sense with the new folder. So it works! Thank you very much! – Physther Jan 05 '18 at 14:56