Ejemplo n.º 1
0
        void ShowExportGUI()
        {
            if (GUILayout.Button("Export"))
            {
                string folderPath = EditorUtility.OpenFolderPanel("Select folder to save to.", "", "");
                if (availableFileFormats[chosenFileFormat] == csvFileEnding)
                {
                    string fullPath = folderPath + "/" + exportFileName + csvFileEnding;
                    CSVParser.Write(fullPath, CSVParser.GetDelimiter(delimiter),
                                    new List <string>(LanguageHandlerEditor.LoadLanguageFile(null, true).Keys), LanguageHandlerEditor.LoadAllLanguageFiles());

                    Debug.Log("Exported CSV file to " + fullPath);
                    this.Close();
                }
                else if (availableFileFormats[chosenFileFormat] == xlsFileEnding)
                {
                    string fullPath = folderPath + "/" + exportFileName + xlsFileEnding;
                    XLSExporter.Write(fullPath, "Languages",
                                      new List <string>(LanguageHandlerEditor.LoadLanguageFile(null, true).Keys), LanguageHandlerEditor.LoadAllLanguageFiles());

                    Debug.Log("Exported XLS file to " + fullPath);
                    this.Close();
                }
                else
                {
                    Debug.LogError("BulkUpdateWindow: Unsupported export format!");
                }
            }
        }
Ejemplo n.º 2
0
        public void TestCSVReadWithWrongDelimiter_Failure()
        {
            var result = CSVParser.ReadFromString(TestCSVDataWithCaret, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));

            Assert.AreEqual(1, result.Count);
            Assert.AreNotEqual(2, result[0].Count);
            Assert.AreNotEqual("TestKey", result[0][0]);
        }
Ejemplo n.º 3
0
 public void TestObsoleteGetDelimiter()
 {
     Assert.AreEqual(CSVExporter.GetDelimiter(CSVDelimiter.COMMA), CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));
     Assert.AreEqual(CSVExporter.GetDelimiter(CSVDelimiter.SEMI_COLON), CSVParser.GetDelimiter(CSVParser.Delimiter.SEMI_COLON));
     Assert.AreEqual(CSVExporter.GetDelimiter(CSVDelimiter.TAB), CSVParser.GetDelimiter(CSVParser.Delimiter.TAB));
     Assert.AreEqual(CSVExporter.GetDelimiter(CSVDelimiter.VERTICAL_BAR), CSVParser.GetDelimiter(CSVParser.Delimiter.VERTICAL_BAR));
     Assert.AreEqual(CSVExporter.GetDelimiter(CSVDelimiter.CARET), CSVParser.GetDelimiter(CSVParser.Delimiter.CARET));
 }
Ejemplo n.º 4
0
        public void TestCSVReadWithComma_Success()
        {
            var result = CSVParser.ReadFromString(TestCSVDataWithComma, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2, result[0].Count);
            Assert.AreEqual("TestKey", result[0][0]);
            Assert.AreEqual("TestValue", result[0][1]);
        }
Ejemplo n.º 5
0
        public void TestCSVReadWithVerticalBar_Success()
        {
            var result = CSVParser.ReadFromString(TestCSVDataWithVerticalBar, CSVParser.GetDelimiter(CSVParser.Delimiter.VERTICAL_BAR));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2, result[0].Count);
            Assert.AreEqual("TestKey", result[0][0]);
            Assert.AreEqual("TestValue", result[0][1]);
        }
Ejemplo n.º 6
0
        public void TestCSVReadWithSemiColon_Success()
        {
            var result = CSVParser.ReadFromString(TestCSVDataWithSemiColon, CSVParser.GetDelimiter(CSVParser.Delimiter.SEMI_COLON));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2, result[0].Count);
            Assert.AreEqual("TestKey", result[0][0]);
            Assert.AreEqual("TestValue", result[0][1]);
        }
Ejemplo n.º 7
0
        public void TestCSVWriteWithCaret_Success()
        {
            var    testData   = GetCsvWriteTestData("TestKey", "TestValue");
            string csv        = CSVParser.WriteToString(CSVParser.GetDelimiter(CSVParser.Delimiter.CARET), testData);
            var    actualData = CSVParser.ReadFromString(csv, CSVParser.GetDelimiter(CSVParser.Delimiter.CARET));

            Assert.AreEqual(testData[0][0], actualData[0][0]);
            Assert.AreEqual(testData[0][1], actualData[0][1]);
        }
        void UpdateFromCSV(string chosenUpdateFile)
        {
            UpdateLanguageFile(CSVParser.Read(chosenUpdateFile, CSVParser.GetDelimiter(delimiter)));

            /*
             * if (parentWindow.translateLanguageWindow != null)
             * {
             *  parentWindow.translateLanguageWindow.ReloadLanguage();
             * }
             */
        }
Ejemplo n.º 9
0
 void OnWatchedFileChanged(object source, FileSystemEventArgs e)
 {
     EditorThreadQueuer.QueueOnMainThread(() => {
         Console.WriteLine("File changed. Reloading...");
         List <List <string> > values = CSVParser.Read(e.FullPath, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));
         LanguageHandlerEditor.UpdateLanguageFile(currentCultureInfo.languageCode, values);
         ReloadLanguage();
         if (Application.isPlaying && LanguageManager.HasInstance)
         {
             LanguageManager.Instance.ChangeLanguage(currentCultureInfo.languageCode);
         }
         Repaint();
     });
 }
        void ExportToCSV(string chosenExportFolder)
        {
            string name  = chosenCulture.englishName + " - " + chosenCulture.languageCode + ".csv";
            var    input = new List <List <string> >();
            Dictionary <string, LocalizedObject> languageItems = LanguageHandlerEditor.LoadParsedLanguageFile(chosenCulture.languageCode, false);

            foreach (var item in languageItems)
            {
                var row = new List <string>();
                row.Add(item.Key);
                row.Add(item.Value.TextValue);
                input.Add(row);
            }
            CSVParser.Write(chosenExportFolder + "/" + name, CSVParser.GetDelimiter(delimiter), input);
        }
Ejemplo n.º 11
0
        void ImportFromCSV(string chosenImportFile)
        {
            List <List <string> > values = CSVParser.Read(chosenImportFile, CSVParser.GetDelimiter(delimiter));

            if (chosenCulture == null)
            {
                Debug.LogError("The language: " + chosenCulture.englishName + " could not be created");
                this.Close();
                return;
            }
            LanguageHandlerEditor.CreateNewLanguage(chosenCulture.languageCode, values);

            if (creationDelegate != null)
            {
                creationDelegate();
                creationDelegate = null;
            }
        }
Ejemplo n.º 12
0
        void ShowImportGUI()
        {
            if (GUILayout.Button("Import"))
            {
                if (availableFileFormats[chosenFileFormat] == csvFileEnding)
                {
                    string file = EditorUtility.OpenFilePanel("Select CSV file.", "", "");
                    if (file != null && file != "")
                    {
                        var values = CSVParser.Read(file, CSVParser.GetDelimiter(delimiter));
                        if (values.Count > 0)
                        {
                            LanguageHandlerEditor.BulkUpdateLanguageFiles(values);
                        }
                    }
                    this.Close();
                }
                else if (availableFileFormats[chosenFileFormat] == xlsFileEnding)
                {
                    string file = EditorUtility.OpenFilePanel("Select XLS file.", "", "");
                    if (file != null && file != "")
                    {
                        var values = XLSExporter.Read(file);
                        if (values.Count > 0)
                        {
                            LanguageHandlerEditor.BulkUpdateLanguageFiles(values);
                        }
                    }
                    this.Close();
                }
                else
                {
                    Debug.LogError("BulkUpdateWindow: Unsupported import format!");
                }

                if (parentWindow.translateLanguageWindow != null)
                {
                    parentWindow.translateLanguageWindow.ReloadLanguage();
                }
            }
        }
Ejemplo n.º 13
0
 public void TestCSVRead_FileNotFoundException()
 {
     CSVParser.Read(string.Empty, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));
 }
Ejemplo n.º 14
0
 public void TestCSVRead_FileNotFoundException()
 {
     Assert.Throws <System.IO.FileNotFoundException>(() => CSVParser.Read(string.Empty, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA)));
 }
Ejemplo n.º 15
0
 public void TestCSVReadEmptyContent_ArgumentException()
 {
     CSVParser.ReadFromString(null, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA));
 }
Ejemplo n.º 16
0
        void UpdateFromCSV(string chosenUpdateFile)
        {
            LanguageHandlerEditor.UpdateLanguageFile(chosenCulture.languageCode, CSVParser.Read(chosenUpdateFile, CSVParser.GetDelimiter(delimiter)));

            if (parentWindow.translateLanguageWindow != null)
            {
                parentWindow.translateLanguageWindow.ReloadLanguage();
            }
        }
Ejemplo n.º 17
0
 public static char GetDelimiter(CSVDelimiter delimiter)
 {
     return(CSVParser.GetDelimiter((CSVParser.Delimiter)delimiter));
 }
Ejemplo n.º 18
0
 public void TestCSVReadEmptyContent_ArgumentException()
 {
     Assert.That(() => CSVParser.ReadFromString(null, CSVParser.GetDelimiter(CSVParser.Delimiter.COMMA)), Throws.ArgumentException);
 }