I have an app with some localization made by adding folders like values, values-es, values-ru etc. In every folder I have file named strings.xml with, guess what, strings.
Some of them need to be in all languages, but some needed just in one for inner needs of the app. But if there is a string in values/strings.xml that is missing in other versions of this file, it causes an error. I tried to add one more file with
<resources>
<string name="key">Value</string>
...
</resources>
with different name, like values/additionalStrings, but it didn’t worked. So I just copied all the strings in all the files to fix the app. But how can I avoid it and store some extra strings in separate .xml?
Additional part of the question:
Also, if it is possible (I guess, it is) to store some more info like
<resources>
<customObject name="myName">
text = "Value"
extraField = 3.14
</customObject >
...
</resources>
in custom xml and get it via usual R.filename.objectName.subFieldName, it would be awesome. How can I do it?
The types of Strings you want to store here are not XML, so it doesn’t really make sense to try to store them inside an XML file. Android is not going to parse the inner contents of an element and make constants in the
Rfile based on what it finds.An alternative approach would be to store your file as plain text, or some other format, like JSON, and put the file in the
rawfolder in your application. Then, you can read it using openRawResource(), and parse it however you need to.