示例#1
0
        private List <Locale> GetLanguagesInSheets(IEnumerable <LocalizationAsset> assets)
        {
            var localizationsTable = new Dictionary <string, List <string> >();

            foreach (LocalizationAsset asset in assets)
            {
                List <List <string> > lines;
                string text = asset.TextAsset.text.Replace("\r\n", "\n");

                if (asset.Format == GoogleDriveDownloadFormat.CSV)
                {
                    lines = CsvReader.Parse(text);
                }
                else
                {
                    lines = TsvReader.Parse(text);
                }

                foreach (List <string> line in lines.SkipWhile(l => l[0] != "Polyglot").Skip(1))
                {
                    string keyName = line[0];

                    if (!string.IsNullOrWhiteSpace(keyName) && line.Count > 1)
                    {
                        List <string> localizations = line.Skip(2).ToList();

                        if (localizationsTable.ContainsKey(keyName))
                        {
                            localizationsTable[keyName] = localizations;
                        }
                        else
                        {
                            localizationsTable.Add(keyName, localizations);
                        }
                    }
                }
            }

            var presentLanguages = new List <Locale>();

            foreach (int lang in Enum.GetValues(typeof(Locale)))
            {
                foreach (List <string> localizations in localizationsTable.Values)
                {
                    if (!string.IsNullOrWhiteSpace(localizations.ElementAtOrDefault(lang)))
                    {
                        presentLanguages.Add((Locale)lang);
                        break;
                    }
                }
            }

            return(presentLanguages);
        }
    private static void ImportTextFile(string text, GoogleDriveDownloadFormat format)
    {
        List <List <string> > rows;

        text = text.Replace("\r\n", "\n");
        if (format == GoogleDriveDownloadFormat.CSV)
        {
            rows = CsvReader.Parse(text);
        }
        else
        {
            rows = TsvReader.Parse(text);
        }
        var canBegin = false;

        for (int rowIndex = 0; rowIndex < rows.Count; rowIndex++)
        {
            var row = rows[rowIndex];
            var key = row[0];

            if (string.IsNullOrEmpty(key) || IsLineBreak(key) || row.Count <= 1)
            {
                //Ignore empty lines in the sheet
                continue;
            }

            if (!canBegin)
            {
                if (key == "Polyglot" || key == "PolyMaster" || key == "BEGIN")
                {
                    canBegin = true;
                }
                continue;
            }

            if (key == "END")
            {
                break;
            }

            //Remove key
            row.RemoveAt(0);
            //Remove description
            row.RemoveAt(0);

            if (languageStrings.ContainsKey(key))
            {
                languageStrings[key] = row;
                continue;
            }
            languageStrings.Add(key, row);
        }
    }
示例#3
0
        internal List <Language> GetLanguagesInSheets(params LocalizationAsset[] assets)
        {
            List <Language> supported = new List <Language>();

            supported.AddRange(Localization.Instance.GetField <List <Language>, Localization>("supportedLanguages"));
            var locTable = new Dictionary <string, List <string> >();

            for (int i = 0; i < assets.Length; i++)
            {
                var asset = assets[i];
                List <List <string> > textData;
                if (asset.Format == GoogleDriveDownloadFormat.CSV)
                {
                    textData = CsvReader.Parse(asset.TextAsset.text.Replace("\r\n", "\n"));
                }
                else
                {
                    textData = TsvReader.Parse(asset.TextAsset.text.Replace("\r\n", "\n"));
                }
                bool isValid = false;
                for (int a = 0; a < textData.Count; a++)
                {
                    List <string> valList = textData[a];
                    string        keyName = valList[0];
                    if (!string.IsNullOrEmpty(keyName) && !LocalizationImporter.IsLineBreak(keyName) && valList.Count > 1)
                    {
                        if (!isValid && keyName.StartsWith("Polyglot"))
                        {
                            isValid = true;
                        }
                        else if (isValid)
                        {
                            valList.RemoveAt(0);
                            valList.RemoveAt(0);
                            if (locTable.ContainsKey(keyName))
                            {
                                locTable[keyName] = valList;
                            }
                            else
                            {
                                locTable.Add(keyName, valList);
                            }
                        }
                    }
                }
            }
            ISet <int> validLanguages = new HashSet <int>();

            foreach (var value in locTable.Values)
            {
                for (int i = 0; i < value.Count; i++)
                {
                    if (!string.IsNullOrEmpty(value.ElementAtOrDefault(i)))
                    {
                        validLanguages.Add(i);
                    }
                }
            }
            supported.Clear();
            for (int i = 0; i < validLanguages.Count; i++)
            {
                supported.Add((Language)validLanguages.ElementAt(i));
            }
            return(supported);
        }