简体   繁体   中英

Strings.xml and values-es in eclipse - Supporting multiple languages

I have a trivia game on the Play Store right now that has 300 questions in it. Each question object in my java code looks like this:

exodus.add(new Question("Aaron", "Abraham", "Jacob", "Joseph", 0, "What was the name of Moses' brother?", -1, "Exodus 7:1-2"));

I am implementing Spanish support in the next release. To do this, after research, I saw the best thing to do would be to take every string in the 300 objects (like in the object I posted above) and put it into the res/values/strings.xml folder. Then, make a res/values-es/strings.xml folder for the Spanish support. After this is done, each of the 300 question objects will now look like this in the java code:

exodus.add(new Question("" + R.string.exodusa1, "" + R.string.exodusb1, "" + R.string.exodusc1, "" + R.string.exodusd1, 0, "" + R.string.exodusq1, -1, "" + R.string.exodusv1));

Where each string in XML will look something like this:

<string name="exodusq1">This would be the text for question 1.</string>
<string name="exodusa1">Etc etc...</string>
etc etc...

This way I am able to support English and Spanish. My question/problem is that I feel like the code is superrrrrr long in my strings.xml files for the English and Spanish. Below is the math to show how long those files are.

  • 300 objects for each language (English and Spanish)
  • Each object has 6 strings
  • That means res/values/strings.xml will have 1800 <string> s
  • That means res/values-es/strings.xml will have 1800 <string> s
  • That means between the 2 strings.xml files, they will have 3600+ <string> s

Am I going about this incorrectly? Or is this just the way it has to be since I am trying to make a trivia game with hundreds of questions support more than one language? Because that is a lot of <string> s.

You're doing it right.... i18n (i - 18 letters - n - internationalisation) is a hard and labour-intensive process. but worth it.

It is worth noting, that you probably don't need to translate the names (are they common in Spanish and English?) and let the system fall back to the default translation for some words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM