Beispiel #1
0
    public static bool LoadCSV(TextAsset asset)
    {
        ByteReader          byteReader = new ByteReader(asset);
        BetterList <string> betterList = byteReader.ReadCSV();

        if (betterList.size < 2)
        {
            return(false);
        }
        betterList[0] = "KEY";
        if (!string.Equals(betterList[0], "KEY"))
        {
            Debug.LogError("Invalid localization CSV file. The first value is expected to be 'KEY', followed by language columns.\nInstead found '" + betterList[0] + "'", asset);
            return(false);
        }
        Localization.mLanguages = new string[betterList.size - 1];
        for (int i = 0; i < Localization.mLanguages.Length; i++)
        {
            Localization.mLanguages[i] = betterList[i + 1];
        }
        Localization.mDictionary.Clear();
        while (betterList != null)
        {
            Localization.AddCSV(betterList);
            betterList = byteReader.ReadCSV();
        }
        return(true);
    }
Beispiel #2
0
    public static bool LoadCSV(TextAsset asset)
    {
        ByteReader          byteReader = new ByteReader(asset);
        BetterList <string> betterList = byteReader.ReadCSV();

        if (betterList.size < 2)
        {
            return(false);
        }
        betterList[0] = "KEY";
        if (!string.Equals(betterList[0], "KEY"))
        {
            return(false);
        }
        Localization.knownLanguages = new string[betterList.size - 1];
        for (int i = 0; i < Localization.knownLanguages.Length; i++)
        {
            Localization.knownLanguages[i] = betterList[i + 1];
        }
        Localization.mDictionary.Clear();
        while (betterList != null)
        {
            Localization.AddCSV(betterList);
            betterList = byteReader.ReadCSV();
        }
        return(true);
    }
Beispiel #3
0
    private static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false)
    {
        if (bytes == null)
        {
            return(false);
        }
        ByteReader          byteReader = new ByteReader(bytes);
        BetterList <string> betterList = byteReader.ReadCSV();

        if (betterList.size < 2)
        {
            return(false);
        }
        betterList.RemoveAt(0);
        string[] array = null;
        if (string.IsNullOrEmpty(Localization.mLanguage))
        {
            Localization.localizationHasBeenSet = false;
        }
        if (!Localization.localizationHasBeenSet || (!merge && !Localization.mMerging) || Localization.mLanguages == null || Localization.mLanguages.Length == 0)
        {
            Localization.mDictionary.Clear();
            Localization.mLanguages = new string[betterList.size];
            if (!Localization.localizationHasBeenSet)
            {
                Localization.mLanguage = PlayerPrefs.GetString("Language", betterList[0]);
                Localization.localizationHasBeenSet = true;
            }
            for (int i = 0; i < betterList.size; i++)
            {
                Localization.mLanguages[i] = betterList[i];
                if (Localization.mLanguages[i] == Localization.mLanguage)
                {
                    Localization.mLanguageIndex = i;
                }
            }
        }
        else
        {
            array = new string[betterList.size];
            for (int j = 0; j < betterList.size; j++)
            {
                array[j] = betterList[j];
            }
            for (int k = 0; k < betterList.size; k++)
            {
                if (!Localization.HasLanguage(betterList[k]))
                {
                    int num = Localization.mLanguages.Length + 1;
                    Array.Resize <string>(ref Localization.mLanguages, num);
                    Localization.mLanguages[num - 1] = betterList[k];
                    Dictionary <string, string[]> dictionary = new Dictionary <string, string[]>();
                    foreach (KeyValuePair <string, string[]> current in Localization.mDictionary)
                    {
                        string[] value = current.Value;
                        Array.Resize <string>(ref value, num);
                        value[num - 1] = value[0];
                        dictionary.Add(current.Key, value);
                    }
                    Localization.mDictionary = dictionary;
                }
            }
        }
        Dictionary <string, int> dictionary2 = new Dictionary <string, int>();

        for (int l = 0; l < Localization.mLanguages.Length; l++)
        {
            dictionary2.Add(Localization.mLanguages[l], l);
        }
        while (true)
        {
            BetterList <string> betterList2 = byteReader.ReadCSV();
            if (betterList2 == null || betterList2.size == 0)
            {
                break;
            }
            if (!string.IsNullOrEmpty(betterList2[0]))
            {
                Localization.AddCSV(betterList2, array, dictionary2);
            }
        }
        if (!Localization.mMerging && Localization.onLocalize != null)
        {
            Localization.mMerging = true;
            Localization.OnLocalizeNotification onLocalizeNotification = Localization.onLocalize;
            Localization.onLocalize = null;
            onLocalizeNotification();
            Localization.onLocalize = onLocalizeNotification;
            Localization.mMerging   = false;
        }
        if (merge)
        {
            if (Localization.onLocalize != null)
            {
                Localization.onLocalize();
            }
            UIRoot.Broadcast("OnLocalize");
        }
        return(true);
    }
Beispiel #4
0
 public unsafe static long $Invoke0(long instance, long *args)
 {
     Localization.AddCSV((BetterList <string>)GCHandledObjects.GCHandleToObject(*args), (string[])GCHandledObjects.GCHandleToPinnedArrayObject(args[1]), (Dictionary <string, int>)GCHandledObjects.GCHandleToObject(args[2]));
     return(-1L);
 }