How to access path like res/values-XX/strings.xml
Google Play wants to localized application. So this must be native for APK. I want to translate my game for all languages. File strings.xml has 70 words and i translated all of them. I created "Plugins/Android/res/values/strings.xml", "../values-en/strings.xml", "../values-fr/strings.xml", "../values-it/strings.xml" etc.
But Android devices don't find this path. I think there is no path. I'm not sure. What is the problem? And How can i fix this problem ?
Exception:
Failed to find mounted volume for /storage/sdcard/Android/data/com.newexample.readxml/files/
My Code:
string PathRes = "Plugins/Android/res";
string PathLanguage = "values"; //It can be "values-en", "values-it", "values-fr" for system language. This isn't important.
string FileName = "strings.xml";
public string GetText (string val)
{
val = val.Trim ().ToLower ().Replace (" ", "_");
try {
string pathXml = Application.persistentDataPath + "/" + PathRes + "/" + PathLanguage + "/" + FileName;
var doc = new XmlDocument ();
doc.Load (pathXml); //Problem is here. The device don't access it.
XmlNode itemNode = doc.SelectSingleNode ("/resources/string[@name = '" + val + "']");
if (itemNode != null) {
return itemNode.InnerText;
} else {
return "";
}
} catch (System.Exception ex) {
P ("Error!!! System using default language path.");
return "";
}
}
Note from Me : Sorry, I don't know English very well.
Answer by WillNode · Sep 02, 2015 at 09:45 AM
you can't access xml file directly, use TextAsset for that.
public TextAsset xmlFile; //Attach XML File here, or load it by Resources.Load
XMLDocument doc;
void Start(){
doc=new XMLDocument();
doc.LoadXml(xmlFile.text);
}
Thanks for answer. So, Can i access "Plugins/Android/res/values/strings.xml" with TextAsset directly? (Not Resources)
yes, and you don't need to place them inside Plugins folder again.
But Google Play wants native localization, so files can be there. Am I wrong ?
hmm. unfortunately i had no experience for google's native localization so far.....