Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by akguldeniz · Apr 25, 2015 at 10:06 AM · androidxmlread

android xml language issue

hi guys i am tryin to make multilanguage. it work well on unity but not working on android device.

 #if UNITY_EDITOR
     LMan = new Lang(Path.Combine(Application.dataPath, "Resources/lang.xml"), currentLang, false);
     #elif UNITY_ANDROID
     LMan = new Lang(Path.Combine(Application.persistentDataPath, "lang.xml"), currentLang, false);
 
 //i tried other ways too, without ifelse etc.;
 
 LMan = new Lang(Path.Combine(Application.dataPath, "Resources/lang.xml"), currentLang, false);



and here is xml load part of code.

 public function setLanguage ( path : String, language : String) {
         var xml : XmlDocument = new XmlDocument();
         xml.Load(path);
         
         Strings = new Hashtable();
         var element : XmlElement = xml.DocumentElement.Item[language];
         if (element) {
             var elemEnum : IEnumerator = element.GetEnumerator();
             while (elemEnum.MoveNext()) {
                 var xmlItem : XmlElement = elemEnum.Current;
                 Strings.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
             }
         } else {
             Debug.LogError("The specified language does not exist: " + language);
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Apr 25, 2015 at 10:38 AM

Assets that are in your project can't be reached via file IO as all assets are packed into asset files inside the apk. Application.persistentDataPath is a location where your app can store data. This location is initially empty. You won't find there anthing you didn't put there first.

You can use Streaming Assets by placing your files inside a folder called "StreamingAssets". That way those files are just packed into the apk (which is just a zip file) instead of getting packed as asset.

Though if the language files should be packed into the project as assets, you have two options:

  • Place them in a "Resources" folder and use Resources.Load to get back a TextAsset.

  • Directly use the asset by declaring a public variable of type "TextAsset" (could be an array) and just assign your xml file(s) in the inspector to this(those) variable(s)

The public variable approach is usually the prefered one. Using the Resources folder has some disadvantages as all assets in Resources folders are fetched right at start. StreamingAssets would work as well, but it's easier to gather / manipulate by endusers as they are directly inside the apk.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image akguldeniz · Apr 25, 2015 at 10:50 AM 0
Share

cheers man it worked. here is working code

     var asset : TextAsset;
     public function setLanguage ( path : String, language : String) {
         asset = Resources.Load("lang") as TextAsset;
         var xml : XmlDocument = new XmlDocument();
         xml.LoadXml(asset.text);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

XmlWriter.Create exception, "Could not find the file..." on Android 0 Answers

Load file on Android 1 Answer

Epic slow android build time, lots of Read/Write enabled sprites! 1 Answer

Get external .xml in mobile 1 Answer

xmlDocument.loadXml/load raises NotImplementedException on android, works in editor 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges