Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- using System.Collections.Generic;
- namespace ModelisaTools
- {
- [InitializeOnLoad]
- public static class Lang
- {
- private static int currentLanguage;
- private static List<string> languages;
- private static List<List<string>> words;
- static Lang ()
- {
- currentLanguage = 0;
- languages = new List<string> ();
- words = new List<List<string>> ();
- if (Directory.Exists (Application.dataPath + "/ModelisaTools/Lang"))
- {
- string[] files = Directory.GetFiles (Application.dataPath + "/ModelisaTools/Lang");
- if (files.Length > 0)
- {
- string langs = "";
- for (int i = 0; i < files.Length; i++)
- {
- ReadFile (files[i]);
- languages.Add (Path.GetFileName (files[i]).Substring (0, 2));
- langs += languages[i];
- if (i < files.Length - 1) langs += ", ";
- }
- DebugConsole.Log ("Lang initialized : " + langs);
- }
- else
- {
- DebugConsole.Log ("Lang initialization failed : no files found.");
- }
- }
- else
- {
- DebugConsole.Log ("ModelisaTools : Lang directory not found !");
- }
- }
- private static void ReadFile (string path)
- {
- List<string> langWords = new List<string> ();
- string[] data = File.ReadAllText (path).Split ('$');
- for (int i = 0; i < data.Length; i++)
- {
- data[i] = data[i].Trim (" \n\t".ToCharArray ());
- if (!string.IsNullOrEmpty (data[i]) && !data[i].StartsWith ("//"))
- {
- langWords.Add (data[i]);
- }
- }
- words.Add (langWords);
- }
- public static string Trad (string str)
- {
- string trad = "";
- if (languages[currentLanguage] == "EN")
- {
- trad = str;
- }
- else
- {
- if (words[languages.IndexOf ("EN")].Contains (str))
- {
- trad = words[currentLanguage][words[languages.IndexOf ("EN")].IndexOf (str)];
- }
- else {
- trad = "TRAD ERROR : " + str;
- }
- }
- return trad;
- }
- public static void DrawLangButton (Rect rect)
- {
- if (GUI.Button (rect, languages[currentLanguage]))
- {
- currentLanguage = (currentLanguage + 1) % languages.Count;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement