Search Unity

[FREE] XML Multi Language System

Discussion in 'Assets and Asset Store' started by silvematt, Jun 29, 2018.

  1. silvematt

    silvematt

    Joined:
    Jul 15, 2016
    Posts:
    160
    MLS (Multi-Language System) is a solution that allows you to have how many languages you need for every type of text inside Unity, starting from a simple text to 3d texts, dropdowns options, textes inside the buttons, whole dialogues, quests etc.

    In the package is included a dynamical “Alert Message” system that works with MLS, to really give you all you can need.

    The system works with XML files, an important and usefully thing is that you can have those files that contains the textes locally (stored on the computer) or hosted on the internet. It’s absolutely your choise, and for switch it you only have to one click a flag. You can also combine both solutions.

    There is no limit of the amount of languages you can add, and adding a new languages will take you just few minutes. Also, there is no limit of the amount of the texts you can insert in the XML file. The Language Manager “travels” in every scene, that means you’ll have the language you selected, for example in the options, for every scene existing in your project, and you can change the language from any scene and see the results applied to every scenes. Adding/Modifing texts will take you few seconds, and you can do it whenever you want without have to touch anything but the interested text from the XML file.

    The documentation will provide you huge explanation on how the system works, how to add new texts and also on how to add new languages with step-by-step tutorials. Source code is included with huge explaination of all the functions
     
  2. Pitou22

    Pitou22

    Joined:
    Sep 23, 2015
    Posts:
    59
    Hello,
    Thanks for sharing your system. Really good documentation !

    I've just upgraded it a little bit to fit in my project :
    - Remove unless Update() function, set an event system to update texts
    - Remove online download, xml files have to be now in a "Resource" folder
    - Add support for multi-line text with '\n'
    - Small optimisations

    Here is my new version ! :)
     

    Attached Files:

    Lumpazy likes this.
  3. Lumpazy

    Lumpazy

    Joined:
    Apr 24, 2018
    Posts:
    45
    Nice work guys. Simple yet effective.
     
    silvematt likes this.
  4. Naxionman1978

    Naxionman1978

    Joined:
    Dec 13, 2017
    Posts:
    4
    Really nice work! Thank you guys!

    But I've got a small problem and I don't know if there is a solution through this system. You see, I want to set a text via script in some point in my game and I have set a string in all my xml files for this occasion. How do I call it from script. An example follows:
    In english.xml I have put this
    Code (CSharp):
    1. <english>
    2.        <string name="unknown">Unknown!</string>
    3. </english>
    And in greek I have put this
    Code (CSharp):
    1. <greek>
    2.        <string name="unknown">Άγνωστο!</string>
    3. </greek>
    And I want to update a text field using the name parameter like this:
    Code (CSharp):
    1. if(something){
    2.        destination.text = ???? The string from the xml ????
    3. } else {
    4.        destination.text = ???? other string from the xml ????
    5. }
     
  5. silvematt

    silvematt

    Joined:
    Jul 15, 2016
    Posts:
    160
    Hello!

    After you've loaded the language:
    Code (CSharp):
    1. destination.text = lang.langReader.getString("unknown");
    In the getString method you've to pass the Key, in this case "unknown".

    If you're wondering what 'lang' is:
    Code (CSharp):
    1.         private LanguageManager lang;
    2.  
    3.         // Use this for initialization
    4.         void Start()
    5.         {
    6.             lang = LanguageManager.instance;
    7.         }
    The result will be the value of the key you've passed in the loaded language.
     
    Naxionman1978 likes this.
  6. Kamalatdin03

    Kamalatdin03

    Joined:
    Nov 30, 2019
    Posts:
    1
  7. aokdev

    aokdev

    Joined:
    Aug 18, 2019
    Posts:
    2
    This pack not working for Android. It worked after the following changes.

    Xml File Location Transfer: Assets/Resources/
    For Example Files:
    Assets/Resources/ENG.xls
    Assets/Resources/TR.xls

    Change in LanguageReader.cs.


    Code (CSharp):
    1. //fıleName: "ENG" >> Filename Without File Extension
    2.   public void SetLocalLanguage(string fıleName, string language)
    3.     {
    4.  
    5.         TextAsset textAsset = (TextAsset)Resources.Load(path, typeof(TextAsset));
    6.         var xml = new XmlDocument();
    7.         xml.LoadXml(textAsset.text);
    8.  
    9.         XML_Strings = new Hashtable();
    10.         var element = xml.DocumentElement[language];
    11.         if (element != null)
    12.         {
    13.             var elemEnum = element.GetEnumerator();
    14.  
    15.             while (elemEnum.MoveNext())
    16.                 XML_Strings.Add((elemEnum.Current as XmlElement).GetAttribute("name"), (elemEnum.Current as XmlElement).InnerText);
    17.  
    18.             update = true;
    19.         }
    20.         else
    21.             Debug.LogError("The specified language does not exist: " + language);
    22.     }
    Change in LanguageManager.cs
    Code (CSharp):
    1.  public void OpenLocalXML(string Language)
    2.     {
    3.         opened = false;
    4.         langReader = null;
    5.         CurrentLanguage = null;
    6.  
    7.         switch (Language)
    8.         {
    9.             case "English":
    10.                 langReader = new LanguageReader("ENG", "English", true);//This changed
    11.                 break;
    12.             case "Turkish":
    13.                 langReader = new LanguageReader("TR", "Turkish", true);//This changed
    14.                 break;
    15.             default:
    16.                 langReader = new LanguageReader("ENG", "English", true);//This changed
    17.                 break;
    18.         }
    19.  
    20.         CurrentLanguage = Language;
    21.  
    22.         opened = true; //The file is opened
    23.  
    24.         StartCoroutine("ResetUpdateState");
    25.  
    26.     }
     
  8. silvematt

    silvematt

    Joined:
    Jul 15, 2016
    Posts:
    160
    From what I remember it works without any issue also on mobile builds as long as you correctly reference the path of the files.

    By the way I strongly advise to not use Resources folder, use Application.persistentDataPath instead.