public static string TranslateString(string tableGuid, string keyGuid, int localeIndex) { if (!initialized) { Initialize(); } var table = Settings.GuidToTable(tableGuid); if (table == null) { return(null); } var entry = table.GuidToEntry(keyGuid); var translation = entry?.Values[localeIndex]; translation = translation?.Replace("\\n", "\n"); return(translation); }
private void CreateSettingsGUI(LocalizationSettings settings) { var tableChoices = settings.TableGuids.Prepend(Guid.Empty.ToString()).ToList(); var defaultIndex = settings.GuidToTableIndex(localizedString.TableGuid) + 1; var tableDropdown = new PopupField <string>("Table", tableChoices, defaultIndex, guid => settings.GuidToTableName(guid, "None"), guid => settings.GuidToTableName(guid, "None")); tableDropdown.name = "TableDropdown"; tableDropdown.RegisterValueChangedCallback(evt => { var table = settings.GuidToTable(evt.newValue); localizedString.TableGuid = evt.newValue; localizedString.Table = table; localizedString.Key = null; localizedString.KeyGuid = null; EditorUtility.SetDirty(localizedString); UpdateKeyVisibility(); }); rootSettingsContainer.Add(tableDropdown); rootSettingsContainer.Add(localizationSettingsContainer = new VisualElement { name = "LocalizationSettingsContainer" }); localizationSettingsContainer.AddGet <VisualElement>("KeyContainer").Do(keyContainer => { keyContainer.AddGet(new TextField("Key") { name = "LocalizationKey", isReadOnly = true }).Do(self => { self.SetEnabled(false); self.BindProperty(keyProperty); }); keyContainer.AddGet(new Button(OnSelectKey) { text = "Select Key", name = "SelectKeyButton" }); }); localizationSettingsContainer.Add(new PropertyField(setterProperty).Do(field => { field.RegisterValueChangeCallback(evt => { var count = localizedString.Setter.GetPersistentEventCount(); for (var i = 0; i < count; i++) { localizedString.Setter.SetPersistentListenerState(i, UnityEventCallState.EditorAndRuntime); } }); })); // Preview section if (localizedString.PreviewLocaleIndex == -1) { localizedString.PreviewLocaleIndex = settings.DefaultLocaleIndex(); } var previewContainer = localizationSettingsContainer.AddGet <VisualElement>("PreviewContainer"); previewContainer.AddGet(previewToggleButton = new Button(TogglePreview) { name = "TogglePreviewButton", text = "Preview" }) .SetClass(localizedString.IsPreviewActive, "active"); previewButtons = new List <Button>(); previewSettings = previewContainer.AddGet <VisualElement>("PreviewSettings").SetClass(!localizedString.IsPreviewActive, "hidden"); previewSettings.AddGet(new ScrollView(ScrollViewMode.Horizontal) { name = "PreviewLocalesContainer" }).Do(container => { for (var i = 0; i < settings.Locales.Count; i++) { var locale = settings.Locales[i]; var localeIndex = i; previewButtons.Add(container.AddGet( new Button(() => SetPreviewLocale(localeIndex)) { text = $"{locale.LocaleCode}" } .SetClass(localeIndex == localizedString.PreviewLocaleIndex, "active") ) ); } }); if (localizedString.IsPreviewActive) { UpdatePreview(); } }