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.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 LocalizationAsset AddLocalizationSheet(string localizationAsset, GoogleDriveDownloadFormat type, string id, bool shadow = false) { var asset = new LocalizationAsset { Format = type, TextAsset = new TextAsset(localizationAsset) }; if (!_lockedAssetCache.ContainsKey(id)) { _lockedAssetCache.Add(id, new LocalizationData(asset, shadow)); } AddLocalizationSheet(asset); return(asset); }
public LocalizationAsset AddLocalizationSheet(string localizationAsset, GoogleDriveDownloadFormat type, string id, bool addToPolyglot = true) { LocalizationAsset asset = new LocalizationAsset { Format = type, TextAsset = new TextAsset(localizationAsset) }; if (!_lockedAssetCache.ContainsKey(id)) { _lockedAssetCache.Add(id, asset); } if (addToPolyglot) { AddLocalizationSheet(asset); } return(asset); }
public static IEnumerator DownloadSheet(string docsId, string sheetId, Action <string> done, GoogleDriveDownloadFormat format = GoogleDriveDownloadFormat.CSV, Func <float, bool> progressbar = null) { if (progressbar != null) { if (progressbar(0)) { done(null); yield break; } } var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/export?format={2}&gid={1}", docsId, sheetId, Enum.GetName(typeof(GoogleDriveDownloadFormat), format).ToLower()); #if UNITY_2017_2_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 (progressbar != null) { if (progressbar(progress)) { done(null); yield break; } } yield return(null); } if (progressbar != null) { if (progressbar(1)) { done(null); yield break; } } #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.\nURL:" + url + "\n" + text); done(null); yield break; } done(text); }
private static void Import(string text, GoogleDriveDownloadFormat format) { ImportTextFile(text, format); }
public LocalizationAsset AddLocalizationSheetFromAssembly(string assemblyPath, GoogleDriveDownloadFormat type, bool addToPolyglot = true) { Utilities.AssemblyFromPath(assemblyPath, out Assembly assembly, out string path); string content = Utilities.GetResourceContent(assembly, path); var locSheet = AddLocalizationSheet(content, type, path, addToPolyglot); if (!_lockedAssetCache.ContainsKey(path)) { _lockedAssetCache.Add(path, locSheet); } return(locSheet); }
public LocalizationAsset AddLocalizationSheetFromAssembly(string assemblyPath, GoogleDriveDownloadFormat type, bool shadow = false) { SiraUtil.Utilities.AssemblyFromPath(assemblyPath, out Assembly assembly, out string path); string content = SiraUtil.Utilities.GetResourceContent(assembly, path); var locSheet = AddLocalizationSheet(content, type, path, shadow); if (!_lockedAssetCache.ContainsKey(path)) { _lockedAssetCache.Add(path, new LocalizationData(locSheet, shadow)); } return(locSheet); }
/// <summary> /// Adds a localization sheet by text. /// </summary> /// <param name="localizationAsset">The stringy asset of the sheet.</param> /// <param name="type">The type of the asset.</param> /// <param name="id">The ID of the asset.</param> /// <param name="shadow">Is it a shadow localization? This means it will not appear unless another source NOT marked as a shadow localization uses a language present. This is to avoid a mod implementing a lot of languages that aren't used anywhere else and them appearing on the list.</param> /// <returns></returns> public LocalizationAsset AddLocalizationSheet(string localizationAsset, GoogleDriveDownloadFormat type, string id, bool shadow = false) { return(_localizer?.AddLocalizationSheet(localizationAsset, type, id, shadow)); }
/// <summary> /// Adds a localization sheet from an assembly rsource. /// </summary> /// <param name="assemblyPath">The path to the resource.</param> /// <param name="type">The type of the asset.</param> /// <param name="shadow">Is it a shadow localization? This means it will not appear unless another source NOT marked as a shadow localization uses a language present. This is to avoid a mod implementing a lot of languages that aren't used anywhere else and them appearing on the list.</param> /// <returns></returns> public LocalizationAsset AddLocalizationSheetFromAssembly(string assemblyPath, GoogleDriveDownloadFormat type, bool shadow = false) { return(_localizer?.AddLocalizationSheetFromAssembly(assemblyPath, type, shadow)); }