void OnGUI() { // Populate the language options LoadLocSetInfo(); // Calculate the position for the language selection screenPos.x = Screen.width - listWidth - 50; screenPos.y = 150; // Draw the language selection buttons Rect listRect = new Rect(screenPos.x, screenPos.y, listWidth, languageDisplay.Length * 24); GUI.Box(listRect, string.Empty, "box"); int newListEntry = GUI.SelectionGrid(listRect, listEntry, languageDisplay, 1); if (languageDisplay.IsValidIndex(newListEntry) && newListEntry != listEntry) { listEntry = newListEntry; } // Set the language // LEManager will only load a language if the requested language is not the one // that is currently loaded LEManager.CurrentLocSet = locSetNames[listEntry]; // Here is an example of how to load a string in code content.text = LEManager.Get(LESampleKeys.FromCodeKey); GUI.Label(new Rect(120, 350, 500, 30), content, labelStyle); }
static void SetCurrentLanguageInManager() { if (LEStringTableEditor.AllLangsVisual.ContainsKey(LEStringTableEditor.CurrentLanguage)) { LEManager.SetCurrentLocSet(LEStringTableEditor.CurrentLanguage, LEStringTableEditor.AllLangsVisual[LEStringTableEditor.CurrentLanguage]); LEManager.LanguageChanged(); } }
public void UpdateLocString() { // Do nothing if the component hasn't been set up yet if (!State.Equals(LELocalizeState.Initialized)) { return; } Text = LEManager.GetLocString(localized_string_key); }
void OnGUI() { if (LEManager.CurrentLocSet.Equals(lastLocUsed) || string.IsNullOrEmpty(localized_string_key)) { return; } Text = LEManager.Get(localized_string_key); lastLocUsed = LEManager.CurrentLocSet; }
void LoadLocSetInfo() { if (locSetNames == null) { locSetNames = new string[] { "en-US-SampleScene", "es-PR-SampleScene", "fr-FR-SampleScene", "it-IT-SampleScene", "de-DE-SampleScene", "ja-JP-SampleScene", "ko-KR-SampleScene", "ru-RU-SampleScene", "ar-SA-SampleScene", "he-IL-SampleScene", "ur-SampleScene" }; } LEManager.CurrentLocSet = locSetNames[0]; GUIStyle listStyle = GUI.skin.button; if (languageDisplay == null) { // Set the display name based on the CultureInfo languageDisplay = new GUIContent[locSetNames.Length]; for (int i = 0; i < languageDisplay.Length; i++) { string culture = locSetNames[i].Replace("-SampleScene", string.Empty); try { if (culture.Equals("ar-SA")) { languageDisplay[i] = new GUIContent(LEManager.Get(LESampleKeys.ar)); } else if (culture.Equals("he-IL")) { languageDisplay[i] = new GUIContent(LEManager.Get(LESampleKeys.he)); } else if (culture.Equals("ur")) { languageDisplay[i] = new GUIContent(LEManager.Get(LESampleKeys.ur)); } else { LECulture cultureInfo = LECultureFactory.Get(culture); languageDisplay[i] = new GUIContent(cultureInfo.NativeName); } } catch { languageDisplay[i] = new GUIContent(culture); } Vector2 size = listStyle.CalcSize(languageDisplay[i]); listWidth = Mathf.Max(listWidth, size.x); } } labelStyle = new GUIStyle(GUI.skin.label); labelStyle.fontSize = 22; labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = new Color(.196f, .196f, .196f); }
void OnGUI() { SetStyles(); size = Vector2.zero; drawHelper.ResetToTop(); Color currentColor = headerColor; Texture2D currentAltBackground = altBackground; Texture2D normalBackground = GUI.skin.textArea.normal.background; drawHelper.DrawMainHeaderLabel(LEConstants.MainHeaderLbl, currentColor, LEConstants.SizeMainHeaderKey); DrawHeader(); drawHelper.DrawSubHeader(LEConstants.AddNewHeaderLbl, currentColor, LEConstants.SizeAddNewHeaderKey); DrawAddNewSection(); drawHelper.DrawSectionSeparator(); drawHelper.DrawSubHeader(LEConstants.LocStringSectionHeader, currentColor, LEConstants.SizeLocStringHeaderKey); languageWidth = CalcMinWithForArray(languages, comboBoxStyle); if (LEStringTableEditor.AllLangsLogical.Count == 0) { content.text = LEConstants.AddNewLanguageMsg; drawHelper.TryGetCachedSize(LEConstants.SizeAddNewLanguageMsgKey, content, labelStyle, out size); EditorGUI.LabelField(new Rect(drawHelper.HorizontalMiddleOfLine() - size.x / 2f, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle); return; } // Check if the new languages and code have been loaded // If not, load them now (fix for Windows) if (languages == null || languageCodes == null) { LoadLanguagesDisplay(); LoadNewLanguagesDisplay(); } // Select the next available language if the current one is invalid if (!languageCodes.Contains(LEStringTableEditor.CurrentLanguage)) { if (languageCodes.IsValidIndex(langIndex - 1)) { SelectLanguage(langIndex - 1); } else { SelectLanguage(0); } } // Draw language drop down content.text = LEConstants.LanguageLbl; size = labelStyle.CalcSize(content); EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle); drawHelper.CurrentLinePosition += size.x + 5; int newIndex = EditorGUI.Popup(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), languageWidth, comboBoxStyle.fixedHeight), langIndex, languages, comboBoxStyle); if (languageCodes.IsValidIndex(newIndex) && newIndex != langIndex) { SelectLanguage(newIndex); } drawHelper.CurrentLinePosition += languageWidth + 2f; // Draw Delete Language Button content.text = LEConstants.DeleteBtn; drawHelper.TryGetCachedSize(LEConstants.SizeDeleteBtnKey, content, GUI.skin.button, out size); if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.PopupTop(), size.x, size.y), content)) { languagesToRemove.Add(languageCodes[langIndex]); if (languageCodes.IsValidIndex(langIndex - 1)) { SelectLanguage(langIndex - 1); } else { SelectLanguage(0); } } // Set the alignment for the current culture selected if (languageCodes.IsValidIndex(langIndex) && currentCulture != null && currentCulture.IsRightToLeft) { keyStyle.alignment = TextAnchor.MiddleRight; valueStyle.alignment = TextAnchor.MiddleRight; isRTL = true; } else { keyStyle.alignment = TextAnchor.MiddleLeft; valueStyle.alignment = TextAnchor.MiddleLeft; isRTL = false; } drawHelper.NewLine(2); DrawNewLocStringField(); drawHelper.NewLine(2); // Draw the string table labels content.text = LEConstants.KeysLbl; size = labelStyle.CalcSize(content); EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle); drawHelper.CurrentLinePosition += boxWidth; content.text = LEConstants.ValuesLbl; size = labelStyle.CalcSize(content); EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle); drawHelper.NewLine(); // Draw each loc string, one on each line if (!languageCodes.IsValidIndex(langIndex) || !LEStringTableEditor.AllLangsVisual.ContainsKey(languageCodes[langIndex])) { return; } if (!groupHeightCollection.TryGetValue(LEStringTableEditor.CurrentLanguage, out groupHeights)) { groupHeights = new Dictionary <string, float>(); } float currentGroupHeightTotal = CalculateGroupHeightsTotal(); scrollViewHeight = drawHelper.HeightToBottomOfWindow(); scrollViewY = drawHelper.TopOfLine(); verticalScrollbarPosition = GUI.BeginScrollView(new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.FullWindowWidth(), scrollViewHeight), verticalScrollbarPosition, new Rect(drawHelper.CurrentLinePosition, scrollViewY, drawHelper.ScrollViewWidth(), currentGroupHeightTotal)); int count = 0; float currentGroupHeight = 0; float beginningHeight = 0; var string_table = LEStringTableEditor.AllLangsLogical[languageCodes[langIndex]]; foreach (var loc_string in string_table) { if (count % 2 != 0) { valueStyle.normal.background = currentAltBackground; keyStyle.normal.background = currentAltBackground; } else { valueStyle.normal.background = normalBackground; keyStyle.normal.background = normalBackground; } groupHeights.TryGetValue(loc_string.Key, out currentGroupHeight); if (currentGroupHeight == 0f || currentGroupHeight.NearlyEqual(drawHelper.LineHeight)) { currentGroupHeight = drawHelper.LineHeight; } if (drawHelper.IsGroupVisible(currentGroupHeight, verticalScrollbarPosition, scrollViewHeight, scrollViewY) || (count == string_table.Count - 1 && verticalScrollbarPosition.y.NearlyEqual(currentGroupHeightTotal - drawHelper.LineHeight))) { beginningHeight = drawHelper.CurrentHeight(); DrawLocString(string_table, loc_string); drawHelper.NewLine(1.1f); currentGroupHeight = drawHelper.CurrentHeight() - beginningHeight; } else { drawHelper.NewLine(currentGroupHeight / drawHelper.LineHeight); } groupHeights.TryAddOrUpdateValue(loc_string.Key, currentGroupHeight); groupHeightCollection.TryAddOrUpdateValue(LEStringTableEditor.CurrentLanguage, groupHeights); count++; } GUI.EndScrollView(); // Remove keys from all langs keysToRemove.ForEach(key => { LEStringTableEditor.RemoveString(key); }); keysToRemove.Clear(); // Rename any keys in other languages foreach (var pair in renamedKeys) { LEStringTableEditor.UpdateKey(pair.Key, pair.Value); } // Send out the renamed key event if (renamedKeys.Count > 0) { LEManager.KeysRenamed(renamedKeys); } renamedKeys.Clear(); // Update any values in current lang foreach (var pair in updatedStringsForCurrent) { LEStringTableEditor.UpdateString(LEStringTableEditor.CurrentLanguage, pair.Key, pair.Value); } if (updatedStringsForCurrent.Count > 0) { LEManager.LocStringChanged(updatedStringsForCurrent.Keys.ToList()); } updatedStringsForCurrent.Clear(); // Delete any languages that were deleted bool shouldRebuildLanguageLists = languagesToRemove.Count > 0; languagesToRemove.ForEach(lang => { LEStringTableEditor.RemoveLanguage(lang); }); languagesToRemove.Clear(); if (shouldRebuildLanguageLists) { LoadLanguagesDisplay(); LoadNewLanguagesDisplay(); AssetDatabase.Refresh(); } }