public void RemoveLocalizationSheet(LocalizationAsset localizationAsset) { var loc = _lockedAssetCache.Where(x => x.Value == localizationAsset || x.Value.TextAsset.text == localizationAsset.TextAsset.text).FirstOrDefault(); if (!loc.Equals(default(KeyValuePair <string, LocalizationAsset>))) { _lockedAssetCache.Remove(loc.Key); } }
private static void DownloadCustomSheet() { var doc = MultiLanguage.Instance.CustomDocument; DownloadGoogleSheet(doc); customSheet = new LocalizationAsset { TextAsset = doc.TextAsset, Format = doc.Format }; }
private static void DownloadMasterSheet() { var doc = MultiLanguage.Instance.PolyglotDocument; DownloadGoogleSheet(doc); masterSheet = new LocalizationAsset { TextAsset = doc.TextAsset, Format = doc.Format }; }
public void AddLocalizationSheet(LocalizationAsset localizationAsset) { var loc = _lockedAssetCache.Where(x => x.Value == localizationAsset || x.Value.TextAsset.text == localizationAsset.TextAsset.text).FirstOrDefault(); if (loc.Equals(default(KeyValuePair <string, LocalizationAsset>))) { return; } Localization.Instance.GetField <List <LocalizationAsset>, Localization>("inputFiles").Add(localizationAsset); LocalizationImporter.Refresh(); }
private static IDictionary <string, string> ToDictionary(this LocalizationAsset asset, IEnumerable <string> keys) { var dict = new Dictionary <string, string>(); foreach (var key in keys) { dict[key] = asset.GetLocalizedString(key); } return(dict); }
public void AddLocalizationSheet(LocalizationAsset localizationAsset, bool shadow = false) { var loc = _lockedAssetCache.Where(x => x.Value.asset == localizationAsset || x.Value.asset.TextAsset.text == localizationAsset.TextAsset.text).FirstOrDefault(); if (loc.Equals(default(KeyValuePair <string, LocalizationAsset>))) { return; } Localization.Instance.InputFiles.Add(localizationAsset); LocalizationImporter.Refresh(); RecalculateLanguages(); }
public void Initialize() { SiraUtil.Utilities.AssemblyFromPath("ExtendedColorSchemes.Resources.locales.csv", out Assembly assembly, out string path); string content = SiraUtil.Utilities.GetResourceContent(assembly, path); var asset = new LocalizationAsset { Format = GoogleDriveDownloadFormat.CSV, TextAsset = new TextAsset(content) }; Localization.Instance.InputFiles.Add(asset); LocalizationImporter.Refresh(); }
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); }
private bool UpdateTextAsset(string documentProperty, LocalizationAsset localizationAsset) { if (localizationAsset == null) { return(false); } var document = serializedObject.FindProperty(documentProperty); var textAssetProps = document.FindPropertyRelative("textAsset"); if (textAssetProps.objectReferenceValue == null) { textAssetProps.objectReferenceValue = localizationAsset.TextAsset; } var filesList = serializedObject.FindProperty("inputFiles"); var found = false; for (int i = 0; i < filesList.arraySize; i++) { var inputFile = filesList.GetArrayElementAtIndex(i); var textAssetProp = inputFile.FindPropertyRelative("textAsset"); var formatProp = inputFile.FindPropertyRelative("format"); if (textAssetProp.objectReferenceValue == localizationAsset.TextAsset && formatProp.enumValueIndex == (int)localizationAsset.Format) { found = true; break; } } if (!found) { var lastIndex = filesList.arraySize; filesList.InsertArrayElementAtIndex(lastIndex); var inputFile = filesList.GetArrayElementAtIndex(lastIndex); var textAssetProp = inputFile.FindPropertyRelative("textAsset"); textAssetProp.objectReferenceValue = localizationAsset.TextAsset; var formatProp = inputFile.FindPropertyRelative("format"); formatProp.enumValueIndex = (int)localizationAsset.Format; return(true); } return(false); }
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); }
private static void DisplayDocsAndSheetId(string title, bool disableId, bool disableOpen, LocalizationAsset sheet, SerializedProperty document, string defaultDocs, string defaultSheet, string defaultTextAssetPath, Action download) { EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField(title, (GUIStyle)"IN TitleText"); EditorGUI.BeginDisabledGroup(disableId); var docsIdProp = document.FindPropertyRelative("docsId"); if (string.IsNullOrEmpty(docsIdProp.stringValue)) { docsIdProp.stringValue = defaultDocs; } EditorGUILayout.PropertyField(docsIdProp); var sheetIdProps = document.FindPropertyRelative("sheetId"); if (string.IsNullOrEmpty(sheetIdProps.stringValue)) { sheetIdProps.stringValue = defaultSheet; } EditorGUILayout.PropertyField(sheetIdProps); var textAssetProps = document.FindPropertyRelative("textAsset"); if (textAssetProps.objectReferenceValue == null && !string.IsNullOrEmpty(defaultTextAssetPath)) { textAssetProps.objectReferenceValue = AssetDatabase.LoadAssetAtPath <TextAsset>(defaultTextAssetPath); } EditorGUILayout.PropertyField(textAssetProps); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(disableOpen); var downloadOnstartProps = document.FindPropertyRelative("downloadOnStart"); EditorGUILayout.PropertyField(downloadOnstartProps); var formatProps = document.FindPropertyRelative("format"); EditorGUILayout.PropertyField(formatProps); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(string.Empty); if (GUILayout.Button("Open")) { var url = string.Format("https://docs.google.com/spreadsheets/d/{0}/edit#gid={1}", docsIdProp.stringValue, sheetIdProps.stringValue); Application.OpenURL(url); } if (GUILayout.Button("Download")) { download(); } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); }
public override void OnInspectorGUI() { if (refresh) { LocalizationImporter.Refresh(); refresh = false; } EditorGUI.BeginChangeCheck(); serializedObject.Update(); EditorGUILayout.LabelField("Polyglot Localization Settings", (GUIStyle)"IN TitleText"); var polyglotPath = GetPrefsString(PathPrefs); if (string.IsNullOrEmpty(polyglotPath)) { polyglotPath = DefaultPolyglotPath; } var changed = false; if (UpdateTextAsset("polyglotDocument", masterSheet)) { changed = true; masterSheet = null; } DisplayDocsAndSheetId("Official Polyglot Master", true, false, masterSheet, serializedObject.FindProperty("polyglotDocument"), OfficialSheet, OfficialGId, polyglotPath, DownloadMasterSheet); EditorGUILayout.Space(); if (UpdateTextAsset("customDocument", customSheet)) { changed = true; customSheet = null; } DisplayDocsAndSheetId("Custom Sheet", false, !ValidateDownloadCustomSheet(), customSheet, serializedObject.FindProperty("customDocument"), GetPrefsString(CustomDocsIdPrefs), GetPrefsString(CustomSheetIdPrefs), GetPrefsString(CustomPathPrefs), DownloadCustomSheet); EditorGUILayout.Space(); EditorGUILayout.LabelField("Localization Settings", (GUIStyle)"IN TitleText"); var iterator = serializedObject.GetIterator(); for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) { if (iterator.propertyPath.Contains("Document")) { continue; } #if !ARABSUPPORT_ENABLED if (iterator.propertyPath == "Localize") { using (new EditorGUI.DisabledGroupScope(true)) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Arabic Support", (GUIStyle)"BoldLabel"); EditorGUILayout.HelpBox("Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag", MessageType.Info); EditorGUILayout.Toggle(new GUIContent("Show Tashkeel", "Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag"), true); EditorGUILayout.Toggle(new GUIContent("Use Hindu Numbers", "Enable Arabic Support with ARABSUPPORT_ENABLED post processor flag"), false); } } #endif using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); } #if !ARABSUPPORT_ENABLED #endif serializedObject.ApplyModifiedProperties(); if (changed || EditorGUI.EndChangeCheck()) { refresh = true; } }
public async void Initialize() { #if DEBUG Stopwatch stopwatch = Stopwatch.StartNew(); #endif int successCount = 0; foreach (var source in _config.Localization.Sources.Where(s => s.Value.Enabled == true)) { WebResponse response = await _webClient.GetAsync(source.Value.URL, CancellationToken.None); if (response.IsSuccessStatusCode) { try { if (!_lockedAssetCache.TryGetValue(source.Key, out LocalizationAsset asset)) { using (MemoryStream ms = new MemoryStream(response.ContentToBytes())) { using (StreamReader reader = new StreamReader(ms)) { asset = new LocalizationAsset { Format = source.Value.Format, TextAsset = new TextAsset(response.ContentToString()) }; } } _lockedAssetCache.Add(source.Key, asset); Localization.Instance.GetField <List <LocalizationAsset>, Localization>("inputFiles").Add(asset); LocalizationImporter.Refresh(); } successCount++; } catch { Plugin.Log.Warn($"Could not parse localization data from {source.Key}"); continue; } } else { Plugin.Log.Warn($"Could not fetch localization data from {source.Key}"); } } #if DEBUG stopwatch.Stop(); Plugin.Log.Info($"Took {stopwatch.Elapsed.TotalSeconds} seconds to download, parse, and load {successCount} localization sheets."); #endif CheckLanguages(); /*List<string> keys = LocalizationImporter.GetKeys(); * * string savePath = Path.Combine(UnityGame.UserDataPath, "SiraUtil", "Localization", "Dumps"); * if (!Directory.Exists(savePath)) * { * Directory.CreateDirectory(savePath); * } * File.WriteAllLines(Path.Combine(savePath, "Keys.txt"), keys.ToArray());*/ /* * List<string> english = new List<string>(); * foreach (var key in keys) * { * var contains = LocalizationImporter.GetLanguagesContains(key); * english.Add(contains[key].First()); * } * File.WriteAllLines(Path.Combine(savePath, "English.txt"), english.ToArray()); */ /* * Localization.Instance.GetField<List<Language>, Localization>("supportedLanguages").Add(Language.French); * Localization.Instance.SelectedLanguage = Language.French;*/ }
public LocalizationData(LocalizationAsset asset, bool shadow) { this.asset = asset; shadowLocalization = shadow; }
/// <summary> /// Removes a localization sheet. /// </summary> /// <param name="localizationAsset"></param> public void RemoveLocalizationSheet(LocalizationAsset localizationAsset) { _localizer?.RemoveLocalizationSheet(localizationAsset); }
/// <summary> /// Adds a localization sheet. /// </summary> /// <param name="localizationAsset"></param> public void AddLocalizationSheet(LocalizationAsset localizationAsset) { _localizer?.AddLocalizationSheet(localizationAsset); }