简体   繁体   English

Eclipse中的Strings.xml和values-es-支持多种语言

[英]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. 我现在在Play商店上有一个琐事游戏,里面有300个问题。 Each question object in my java code looks like this: 我的Java代码中的每个问题对象如下所示:

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. 为此,经过研究,我发现最好的方法是将300个对象中的每个字符串(就像上面发布的对象一样)放入res/values/strings.xml文件夹中。 Then, make a res/values-es/strings.xml folder for the Spanish support. 然后,为西班牙支持创建一个res/values-es/strings.xml文件夹。 After this is done, each of the 300 question objects will now look like this in the java code: 完成此操作后,现在在Java代码中,这300个问题对象中的每一个都将如下所示:

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: XML中的每个字符串如下所示:

<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. 我的问题/问题是,我觉得自己的代码是superrrrrr长在我strings.xml为英语和西班牙语的文件。 Below is the math to show how long those files are. 下面是显示这些文件多长时间的数学公式。

  • 300 objects for each language (English and Spanish) 每种语言300个对象(英语和西班牙语)
  • Each object has 6 strings 每个对象有6个字符串
  • That means res/values/strings.xml will have 1800 <string> s 这意味着res/values/strings.xml将具有1800 <string>
  • That means res/values-es/strings.xml will have 1800 <string> s 这意味着res/values-es/strings.xml将具有1800 <string>
  • That means between the 2 strings.xml files, they will have 3600+ <string> s 这意味着在2个strings.xml文件之间,它们将具有3600+ <string>

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. 因为那是很多<string>

You're doing it right.... i18n (i - 18 letters - n - internationalisation) is a hard and labour-intensive process. 您做对了...。i18n(i-18个字母-n-国际化)是一个艰苦而费力的过程。 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. 值得注意的是,您可能不需要翻译名称(它们在西班牙语和英语中是常见的吗?),而是让系统将某些单词还原为默认翻译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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