コード例 #1
0
    public static LanguagePack LoadToPack(Language language)
    {
        CurrentLanguage = language;

        try
        {
            string       loadName = System.Enum.GetName(typeof(Language), language);
            string       filePath = LanguagePackDirectory + loadName;
            LanguagePack pk       = new LanguagePack();

            // Read in the STRING contents of xmlFile (TextAsset)
            TextAsset xmlFile;
            string    t;

            if (LanguagePackDirectory.StartsWith("/Resources"))
            {
                filePath = filePath.Substring(11);
                xmlFile  = (TextAsset)Resources.Load(filePath, typeof(TextAsset));
                t        = xmlFile.text;
            }
            else
            {
                StreamReader sr = new StreamReader(Application.dataPath + filePath + ".txt");
                t = sr.ReadToEnd();
                sr.Close();
            }

            using (StringReader f = new StringReader(t))
            {
                string line;
                while ((line = f.ReadLine()) != null)
                {
                    try
                    {
                        pk.AddNewString((string)(line.Split(new string[] { " = " }, System.StringSplitOptions.None)[0]), line.Split(new string[] { " = " }, System.StringSplitOptions.None)[1]);
                        //Debug.Log(line);
                    }
                    catch
                    {
                        if (line.Length > 0)
                        {
                            LanguagePackDirectory = line;
                        }
                    }
                }
            }

            PackLoaded = true;

            return(pk);
        } catch {
            Debug.Log("No File Was Found! Make sure the language file you are trying to load exists!");

            PackLoaded = false;

            return(null);
        }
    }
コード例 #2
0
    public static void AddKeysFromMaster(Language master, Language slave)
    {
        masterPack = LoadToPack (master);
        slavePack = LoadToPack (slave);

        // Compare and Add

        for (int i = 0; i < masterPack.Keys.Count; i++) {
            if (!slavePack.Keys.Contains (masterPack.Keys [i])) {
                slavePack.AddNewString (masterPack.Keys [i], masterPack.Strings [i]);
            }
        }

        loadedLanguagePack = slavePack;
    }
コード例 #3
0
    public static void AddKeysFromMaster(Language master, Language slave)
    {
        masterPack = LoadToPack(master);
        slavePack  = LoadToPack(slave);

        // Compare and Add

        for (int i = 0; i < masterPack.Keys.Count; i++)
        {
            if (!slavePack.Keys.Contains(masterPack.Keys[i]))
            {
                slavePack.AddNewString(masterPack.Keys[i], masterPack.Strings[i]);
            }
        }

        loadedLanguagePack = slavePack;
    }
コード例 #4
0
    public static LanguagePack LoadToPack(Language language)
    {
        CurrentLanguage = language;

        try
        {
            string loadName = System.Enum.GetName(typeof(Language), language);
            string filePath = LanguagePackDirectory + loadName;
            LanguagePack pk = new LanguagePack();

            // Read in the STRING contents of xmlFile (TextAsset)
            TextAsset xmlFile;
            string t;

            if(LanguagePackDirectory.StartsWith("/Resources"))
            {
                filePath = filePath.Substring(11);
                xmlFile = (TextAsset)Resources.Load(filePath, typeof(TextAsset));
                t = xmlFile.text;
            }
            else
            {
                StreamReader sr = new StreamReader(Application.dataPath + filePath + ".txt");
                t = sr.ReadToEnd();
                sr.Close();
            }

            using(StringReader f = new StringReader(t))
            {
                string line;
                while((line = f.ReadLine()) != null)
                {
                    try
                    {
                        pk.AddNewString((string)(line.Split(new string[] { " = " }, System.StringSplitOptions.None)[0]), line.Split(new string[] { " = " }, System.StringSplitOptions.None)[1]);
                        //Debug.Log(line);
                    }
                    catch
                    {
                        if(line.Length > 0)
                            LanguagePackDirectory = line;
                    }
                }
            }

            PackLoaded = true;

            return pk;
        } catch {
            Debug.Log("No File Was Found! Make sure the language file you are trying to load exists!");

            PackLoaded = false;

            return null;
        }
    }