Exemplo n.º 1
0
        private void Import()
        {
            var dat = target as LocalizeAssetGoogleSheet;

            var parser = new SpreadsheetParser.GoogleParser(dat.googleSettings, dat.googleSheetName);

            //refresh database
            string error = "";

            if (!parser.GenerateDatabase(ref error))
            {
                EditorUtility.DisplayDialog("Error", error, "OK");
                return;
            }

            //deserialize
            var dataLookup = parser.DeserializeAllSheets <Item>(null);

            //fill in data
            var tableList = new List <LocalizeAsset.TableData>();

            foreach (var pair in dataLookup)
            {
                string      language = pair.Key;
                List <Item> items    = pair.Value;

                var table = new LocalizeAsset.TableData();

                //TODO: check if platform
                table.name      = language;
                table.entryType = LocalizeAsset.TableEntryType.Language;

                //Populate entries
                var entryList = new List <LocalizeAsset.Entry>();

                foreach (var item in items)
                {
                    entryList.Add(new LocalizeAsset.Entry()
                    {
                        key = item.Key, text = item.Value, param = item.Params
                    });
                }

                table.entries = entryList.ToArray();

                tableList.Add(table);
            }

            dat.tables = tableList.ToArray();

            EditorUtility.SetDirty(dat);
        }
Exemplo n.º 2
0
        public static bool ApplyAsset(LocalizeAssetExcel localize, ref string error)
        {
            var excelParser = new SpreadsheetParser.ExcelParser(localize.excelFilePath);

            if (excelParser.sheetCount == 0)
            {
                error = "No sheets are found.";
                return(false);
            }

            var tableList = new List <LocalizeAsset.TableData>();

            var dataLookup = excelParser.DeserializeAllSheets <Item>(null);

            foreach (var pair in dataLookup)
            {
                string      language = pair.Key;
                List <Item> items    = pair.Value;

                var table = new LocalizeAsset.TableData();

                //TODO: check if platform
                table.name      = language;
                table.entryType = LocalizeAsset.TableEntryType.Language;

                //Populate entries
                var entryList = new List <LocalizeAsset.Entry>();

                foreach (var item in items)
                {
                    entryList.Add(new LocalizeAsset.Entry()
                    {
                        key = item.Key, text = item.Value, param = item.Params
                    });
                }

                table.entries = entryList.ToArray();

                tableList.Add(table);
            }

            localize.tables = tableList.ToArray();

            EditorUtility.SetDirty(localize);

            AssetDatabase.SaveAssets();

            return(true);
        }