public static bool KeyExist(string key) { var languages = LocalizationImporter.GetLanguages(key); var selected = (int)Instance.selectedLanguage; return(languages.Count > 0 && Instance.selectedLanguage >= 0 && selected < languages.Count); }
private void DrawAutoComplete(SerializedProperty property) { var localizedStrings = LocalizationImporter.GetLanguagesStartsWith(property.stringValue); if (localizedStrings.Count == 0) { localizedStrings = LocalizationImporter.GetLanguagesContains(property.stringValue); } var selectedLanguage = (int)MultiLanguage.Instance.SelectedLanguage; showAutoComplete.target = EditorGUILayout.Foldout(showAutoComplete.target, "Auto-Complete"); if (EditorGUILayout.BeginFadeGroup(showAutoComplete.faded)) { EditorGUI.indentLevel++; var height = EditorGUIUtility.singleLineHeight * (Mathf.Min(localizedStrings.Count, 6) + 1); scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(height)); foreach (var local in localizedStrings) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(local.Key); if (GUILayout.Button(local.Value[selectedLanguage], "CN CountBadge")) { property.stringValue = local.Key; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); }
static public int GetLanguages_s(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif System.String a1; checkType(l, 1, out a1); var ret = LocalizationImporter.GetLanguages(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
static public int Refresh_s(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif LocalizationImporter.Refresh(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
private void DrawValuesAutoComplete(SerializedProperty property, string stringValue) { Dictionary <string, string> localizedStrings = LocalizationImporter.GetLanguageValues(stringValue); if (localizedStrings.Count == 0) { localizedStrings = LocalizationImporter.GetLanguagesContains(stringValue); } showValuesAutoComplete.target = EditorGUILayout.Foldout(showValuesAutoComplete.target, "Auto-Complete"); if (EditorGUILayout.BeginFadeGroup(showValuesAutoComplete.faded)) { EditorGUI.indentLevel++; float height = EditorGUIUtility.singleLineHeight * (Mathf.Min(localizedStrings.Count, 6) + 1); this.scrollValues = EditorGUILayout.BeginScrollView(this.scrollValues, GUILayout.Height(height)); foreach (KeyValuePair <string, string> local in localizedStrings) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(local.Key); if (GUILayout.Button(local.Value, contentStyle)) { property.stringValue = local.Key; this.zhString = local.Value; GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); }
public static string Get(string key, Language language) { var languages = LocalizationImporter.GetLanguages(key); var selected = (int)language; if (languages.Count > 0 && selected >= 0 && selected < languages.Count) { var currentString = languages[selected]; if (string.IsNullOrEmpty(currentString) || LocalizationImporter.IsLineBreak(currentString)) { Debug.LogWarning("Could not find key " + key + " for current language " + language + ". Falling back to " + Instance.fallbackLanguage + " with " + languages[(int)Instance.fallbackLanguage]); selected = (int)Instance.fallbackLanguage; currentString = languages[selected]; } #if ARABSUPPORT_ENABLED if (selected == (int)Language.Arabic) { return(ArabicSupport.ArabicFixer.Fix(currentString, instance.showTashkeel, instance.useHinduNumbers)); } #endif return(currentString); } return(string.Format(KeyNotFound, key)); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { for (int index = 0; index < importedAssets.Length; index++) { var str = importedAssets[index]; if (str.EndsWith(".csv") && str.Contains("Localization")) { LocalizationImporter.Refresh(); } } }
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(); }
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 override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); serializedObject.Update(); SerializedProperty iterator = serializedObject.GetIterator(); LocalizedText text = target as LocalizedText; if (text != null) { if (this.zhString != text.GetText()) { this.zhString = text.GetText(); } text.SerializeZhText(this.zhString); } for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) { if (iterator.name == "m_zhText") { EditorGUILayout.LabelField("zhText", iterator.stringValue, new GUILayoutOption[0]); } else if (iterator.name == "m_key") { EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]); string key = iterator.stringValue; string localizedString = LocalizationImporter.GetLanguages(key); if (string.IsNullOrEmpty(zhString)) { zhString = localizedString; } EditorGUILayout.LabelField("中文", localizedString, new GUILayoutOption[0]); if (!string.IsNullOrEmpty(zhString) && zhString != localizedString) { DrawValuesAutoComplete(iterator, zhString); } } } serializedObject.ApplyModifiedProperties(); if (EditorGUI.EndChangeCheck()) { if (text != null) { text.OnLocalize(); } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { for (int index = 0; index < importedAssets.Length; index++) { string str = importedAssets[index]; //Debug.Log("str: " + str); if (str.EndsWith(".lua") && str.Contains("localization")) { Debug.Log("LocalizationImporter.Refresh"); LocalizationImporter.Refresh(); } } }
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 void OnLocalize() { #if UNITY_EDITOR var flags = m_text != null ? m_text.hideFlags : HideFlags.None; if (m_text != null) { m_text.hideFlags = HideFlags.DontSave; } #endif SetText(LocalizationImporter.GetLanguages(m_key)); #if UNITY_EDITOR if (m_text != null) { m_text.hideFlags = flags; } #endif }
protected override void OnDestroy() { LocalizationImporter.OnDestroy(); base.OnDestroy(); }
private bool KeyHasValueForLanguage(string key, Locale language) { return(!string.IsNullOrWhiteSpace(LocalizationImporter.GetLanguages(key).ElementAtOrDefault((int)language))); }
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; } }
private void OnClick() { StartCoroutine(LocalizationImporter.DownloadPolyglotSheet(UpdateProgressbar)); }
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 static List <string> GetKeys() { return(LocalizationImporter.GetKeys()); }
private void Awake() { StartCoroutine(LocalizationImporter.DownloadCustomSheet()); }
internal List <Language> GetLanguagesInSheets(params LocalizationAsset[] assets) { List <Language> supported = new List <Language>(); supported.AddRange(Localization.Instance.GetField <List <Language>, Localization>("supportedLanguages")); var locTable = new Dictionary <string, List <string> >(); for (int i = 0; i < assets.Length; i++) { var asset = assets[i]; List <List <string> > textData; if (asset.Format == GoogleDriveDownloadFormat.CSV) { textData = CsvReader.Parse(asset.TextAsset.text.Replace("\r\n", "\n")); } else { textData = TsvReader.Parse(asset.TextAsset.text.Replace("\r\n", "\n")); } bool isValid = false; for (int a = 0; a < textData.Count; a++) { List <string> valList = textData[a]; string keyName = valList[0]; if (!string.IsNullOrEmpty(keyName) && !LocalizationImporter.IsLineBreak(keyName) && valList.Count > 1) { if (!isValid && keyName.StartsWith("Polyglot")) { isValid = true; } else if (isValid) { valList.RemoveAt(0); valList.RemoveAt(0); if (locTable.ContainsKey(keyName)) { locTable[keyName] = valList; } else { locTable.Add(keyName, valList); } } } } } ISet <int> validLanguages = new HashSet <int>(); foreach (var value in locTable.Values) { for (int i = 0; i < value.Count; i++) { if (!string.IsNullOrEmpty(value.ElementAtOrDefault(i))) { validLanguages.Add(i); } } } supported.Clear(); for (int i = 0; i < validLanguages.Count; i++) { supported.Add((Language)validLanguages.ElementAt(i)); } return(supported); }
private static void OpenWindow() { LocalizationImporter window = UnityEditor.EditorWindow.GetWindow <LocalizationImporter>(); window.titleContent.text = "Translation Importer"; }