using UnityEditor; using UnityEngine; namespace Crowdin.Editor.UnityLocalization { using Plugin.Helpers.PluginLocalization; using Plugin.Helpers.UnityLocalization; using Plugin.Models; using Plugin.Operations; using Plugin.Server_API.Helpers; public class PullStringTranslationsToUnityTranslation : BasePopupEditor { [MenuItem("Tools/Crowdin/Pull string translations from Crowdin", false, 101)] public static void OpenExportPopup() { InitPopup( LocalizationHelper.GetLocalStringByKey(LocalKeys.pull_string_translations_popup_title) ); } private TableSelector tableSelector; private BranchSelector branchSelector; private bool togglePreserveEntryIdsOnImport; protected override void OnEnable() { base.OnEnable(); tableSelector = TableSelector.CreateForStringTables(); branchSelector = BranchSelector.CreateAndLoadSettings(lifetime.Token); togglePreserveEntryIdsOnImport = SettingsHelper.GetToggleStatus_PreserveEntryIdsOnImport(); if (SettingsHelper.GetProjectType() is ProjectType.StringBased) { branchSelector.RefreshBranchesList(); // don't await, separate thread task } } protected override void OnDisable() { base.OnDisable(); tableSelector?.Dispose(); branchSelector?.Dispose(); SettingsHelper.SetToggleStatus_PreserveEntryIdsOnImport(togglePreserveEntryIdsOnImport); } private void OnGUI() { if (!isBusy) { bool isProjectStringBased = SettingsHelper.GetProjectType() is ProjectType.StringBased; tableSelector.DrawLayout(); if (isProjectStringBased) { branchSelector.DrawLayout(); } togglePreserveEntryIdsOnImport = UIHelper.AddToggle_PreserveEntryIdsOnImport(togglePreserveEntryIdsOnImport); GUILayout.Space(10); if (GUILayout.Button( LocalizationHelper.GetLocalStringByKey(LocalKeys.pull_string_translations_popup_title))) { if (!IsProjectSelected()) { return; } if (!UnityLocalizationHelper.IsHavePluginStringsTables()) { status.Clear(); status.AppendLine(LocalizationHelper.GetLocalStringByKey(LocalKeys.no_str_tables)); return; } if (tableSelector.NoTablesAreSelected()) { DialogUtility.NoTablesAreSelected(); return; } SettingsHelper.SetToggleStatus_PreserveEntryIdsOnImport(togglePreserveEntryIdsOnImport); int? branchId = isProjectStringBased ? branchSelector.GetSelectedBranchId() : null; tableSelector.SaveSettings(); branchSelector.SaveSettings(); var options = new PullOptions( tableSelector.ResolveTables(), branchId, togglePreserveEntryIdsOnImport); RunOperation( (progress, cancellationToken) => PullStrings.RunAsync(options, progress, cancellationToken), result => { }); } } OnGUIStatusLabel(); } } }