public void LoadCsv(string csvData, string[] languages, string[] keys, string[,] values) { // Arrange using (var rdr = new System.IO.StringReader(csvData)) { //// Act var localisationData = LocalisationData.LoadCsv(rdr); //// Assert Assert.AreEqual(languages.Length, localisationData.Languages.Count, "Languages not setup as expected"); Assert.AreEqual(keys.Length, localisationData.Entries.Count, "Entries not setup as expected"); foreach (var language in languages) { Assert.IsTrue(localisationData.GetLanguage(language) != null, "Missing language " + language); } for (var i = 0; i < keys.Length; i++) { var key = keys[i]; Assert.IsTrue(localisationData.GetEntry(key) != null, "Missing entry " + key); for (var l = 0; l < languages.Length; l++) { var language = languages[l]; Assert.AreEqual(values[i, l], localisationData.GetText(key, language), "Values are not the same."); } } } }
protected void DrawTools() { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField(new GUIContent("Import / Export", ""), EditorStyles.boldLabel); _importExportHelpRect = EditorHelper.ShowHideableHelpBox("GameFramework.LocalisationEditorWindow.ImportExport", "If you would like to edit the data outside Unity then you can import from and export to .csv (text) files. Entries from any imported file will be merged with existing entries, replacing any keys that already exist with a similar name.\n\nIf you have previously used .csv files for localisation then you should use the import button to import old files into the new localisation system", _importExportHelpRect); if (GUILayout.Button("Import csv", EditorStyles.miniButton)) { var newFileName = EditorUtility.OpenFilePanel("Select a .csv localisation file", _importExportFilename, "csv"); if (!string.IsNullOrEmpty(newFileName)) { _importExportFilename = newFileName; var importedLocalisationData = LocalisationData.LoadCsv(_importExportFilename); if (importedLocalisationData != null) { Undo.RecordObject(_targetLocalisationData, "Import Localisation Csv"); _targetLocalisationData.Merge(importedLocalisationData); _targetChanged = true; EditorUtility.DisplayDialog("Localisation Import", string.Format("Import Complete!\n\nImported {0} languages and {1} entries.", importedLocalisationData.Languages.Count, importedLocalisationData.Entries.Count), "Ok"); } else { EditorUtility.DisplayDialog("Localisation Import", "Import failed!\n\nSee the console window for further details.", "Ok"); } } } if (GUILayout.Button("Export csv", EditorStyles.miniButton)) { var newFileName = EditorUtility.SaveFilePanel("Select a .csv localisation file", _importExportFilename, "localisation", "csv"); if (!string.IsNullOrEmpty(newFileName)) { _importExportFilename = newFileName; if (_targetLocalisationData.WriteCsv(_importExportFilename)) { EditorUtility.DisplayDialog("Localisation Export", "Export complete!", "Ok"); } else { EditorUtility.DisplayDialog("Localisation Export", "Export failed!\n\nSee the console window for further details.", "Ok"); } } } EditorGUILayout.EndVertical(); }