private static void DownloadGoogleSheet(string docsId, string sheetId, LocalizationAssetFormat format, TextAsset textAsset) { EditorUtility.DisplayCancelableProgressBar("Download", "Downloading...", 0); var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/export?format={2}&gid={1}", docsId, sheetId, Enum.GetName(typeof(LocalizationAssetFormat), format).ToLower()); Debug.Log(url); #if UNITY_2017_1_OR_NEWER var www = UnityWebRequest.Get(url); www.SendWebRequest(); #elif UNITY_5_5_OR_NEWER var www = UnityWebRequest.Get(url); www.Send(); #else var www = new WWW(url); #endif while (!www.isDone) { #if UNITY_5_5_OR_NEWER var progress = www.downloadProgress; #else var progress = www.progress; #endif if (EditorUtility.DisplayCancelableProgressBar("Download", "Downloading...", progress)) { return; } } EditorUtility.ClearProgressBar(); var path = textAsset != null?AssetDatabase.GetAssetPath(textAsset) : null; if (string.IsNullOrEmpty(path)) { path = EditorUtility.SaveFilePanelInProject("Save Localization", "", "txt", "Please enter a file name to save the csv to", path); } if (string.IsNullOrEmpty(path)) { return; } #if UNITY_5_5_OR_NEWER var text = www.downloadHandler.text; #else var text = www.text; #endif if (text.StartsWith("<!")) { Debug.LogError("Google sheet could not be downloaded\n" + text); return; } File.WriteAllText(path, text); Debug.Log("Importing " + path); AssetDatabase.ImportAsset(path); LocalizationImporter.Refresh(); }
public static void ImportTextFile(string text, LocalizationAssetFormat format) { List <List <string> > rows; text = text.Replace("\r\n", "\n"); if (format == LocalizationAssetFormat.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.StartsWith("Polyglot") || key.StartsWith("PolyMaster") || key.StartsWith("BEGIN")) { canBegin = true; continue; } } if (!canBegin) { continue; } if (key.StartsWith("END")) { break; } //Remove key row.RemoveAt(0); //Remove description row.RemoveAt(0); if (languageStrings.ContainsKey(key)) { Debug.Log("The key '" + key + "' already exist, but is now overwritten"); languageStrings[key] = row; continue; } languageStrings.Add(key, row); } }
public static void ImportTextFile(string text, LocalizationAssetFormat format) { var lines = text.Split('\n'); var canBegin = false; var csv = format == LocalizationAssetFormat.CSV; for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++) { var line = lines[lineIndex]; if (!canBegin) { if (line.StartsWith("Polyglot") || line.StartsWith("PolyMaster") || line.StartsWith("BEGIN")) { canBegin = true; continue; } } if (!canBegin) { continue; } if (line.StartsWith("END")) { break; } var split = csv ? ',' : '\t'; var keys = line.Split(split).ToList(); var key = keys[0]; if (string.IsNullOrEmpty(key) || IsLineBreak(key) || keys.Count <= 1) { //Ignore empty lines in the sheet continue; } //Remove key keys.RemoveAt(0); //Remove description keys.RemoveAt(0); if (languageStrings.ContainsKey(key)) { Debug.Log("The key '" + key + "' already exist, but is now overwritten"); languageStrings[key] = keys; continue; } languageStrings.Add(key, keys); } }