mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 02:40:20 +00:00 
			
		
		
		
	Enhance language selection with validation and feedback for the localization process
This commit is contained in:
		
							parent
							
								
									35c28913e3
								
							
						
					
					
						commit
						3528535b3f
					
				@ -2,6 +2,7 @@
 | 
				
			|||||||
@using AIStudio.Settings
 | 
					@using AIStudio.Settings
 | 
				
			||||||
@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogI18N>
 | 
					@inherits AssistantBaseCore<AIStudio.Dialogs.Settings.SettingsDialogI18N>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidatingTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" SelectionUpdated="_ => this.OnChangedLanguage()" />
 | 
				
			||||||
<ConfigurationSelect OptionDescription="Language plugin used for comparision" SelectedValue="@(() => this.selectedLanguagePluginId)" Data="@ConfigurationSelectDataFactory.GetLanguagesData()" SelectionUpdate="@(async void (id) => await this.OnLanguagePluginChanged(id))" OptionHelp="Select the language plugin used for comparision."/>
 | 
					<ConfigurationSelect OptionDescription="Language plugin used for comparision" SelectedValue="@(() => this.selectedLanguagePluginId)" Data="@ConfigurationSelectDataFactory.GetLanguagesData()" SelectionUpdate="@(async void (id) => await this.OnLanguagePluginChanged(id))" OptionHelp="Select the language plugin used for comparision."/>
 | 
				
			||||||
@if (this.isLoading)
 | 
					@if (this.isLoading)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -76,6 +77,14 @@ else if (!this.isLoading && string.IsNullOrWhiteSpace(this.loadingIssue))
 | 
				
			|||||||
        </PagerContent>
 | 
					        </PagerContent>
 | 
				
			||||||
    </MudTable>
 | 
					    </MudTable>
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    <EnumSelection T="CommonLanguages" NameFunc="@(language => language.NameSelecting())" @bind-Value="@this.selectedTargetLanguage" ValidateSelection="@this.ValidatingTargetLanguage" Icon="@Icons.Material.Filled.Translate" Label="Target language" AllowOther="@true" OtherValue="CommonLanguages.OTHER" @bind-OtherInput="@this.customTargetLanguage" ValidateOther="@this.ValidateCustomLanguage" LabelOther="Custom target language" />
 | 
					    @if (this.selectedTargetLanguage is CommonLanguages.EN_US)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        <MudJustifiedText Typo="Typo.body1" Class="mb-6">
 | 
				
			||||||
 | 
					            Please note: neither is a translation needed nor performed for the English (USA). Anyway, you might want to generate the related Lua code.
 | 
				
			||||||
 | 
					        </MudJustifiedText>
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        <ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
 | 
					        <ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -23,9 +23,11 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    protected override bool AllowProfiles => false;
 | 
					    protected override bool AllowProfiles => false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected override bool ShowResult => false;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    protected override IReadOnlyList<IButtonData> FooterButtons => [];
 | 
					    protected override IReadOnlyList<IButtonData> FooterButtons => [];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    protected override string SubmitText => "Localize AI Studio";
 | 
					    protected override string SubmitText => "Localize AI Studio & generate the Lua code";
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    protected override Func<Task> SubmitAction => this.LocalizeText;
 | 
					    protected override Func<Task> SubmitAction => this.LocalizeText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,6 +41,8 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
            this.selectedTargetLanguage = CommonLanguages.AS_IS;
 | 
					            this.selectedTargetLanguage = CommonLanguages.AS_IS;
 | 
				
			||||||
            this.customTargetLanguage = string.Empty;
 | 
					            this.customTargetLanguage = string.Empty;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        _ = this.OnChangedLanguage();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    protected override bool MightPreselectValues()
 | 
					    protected override bool MightPreselectValues()
 | 
				
			||||||
@ -61,6 +65,8 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
    private bool localizationPossible;
 | 
					    private bool localizationPossible;
 | 
				
			||||||
    private string searchString = string.Empty;
 | 
					    private string searchString = string.Empty;
 | 
				
			||||||
    private Guid selectedLanguagePluginId;
 | 
					    private Guid selectedLanguagePluginId;
 | 
				
			||||||
 | 
					    private ILanguagePlugin? selectedLanguagePlugin;
 | 
				
			||||||
 | 
					    private bool isTranslationNeeded;
 | 
				
			||||||
    private Dictionary<string, string> addedKeys = [];
 | 
					    private Dictionary<string, string> addedKeys = [];
 | 
				
			||||||
    private Dictionary<string, string> removedKeys = [];
 | 
					    private Dictionary<string, string> removedKeys = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -69,6 +75,7 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
    protected override async Task OnInitializedAsync()
 | 
					    protected override async Task OnInitializedAsync()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        await base.OnInitializedAsync();
 | 
					        await base.OnInitializedAsync();
 | 
				
			||||||
 | 
					        await this.OnLanguagePluginChanged(this.selectedLanguagePluginId);
 | 
				
			||||||
        await this.LoadData();
 | 
					        await this.LoadData();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -77,12 +84,36 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
    private async Task OnLanguagePluginChanged(Guid pluginId)
 | 
					    private async Task OnLanguagePluginChanged(Guid pluginId)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.selectedLanguagePluginId = pluginId;
 | 
					        this.selectedLanguagePluginId = pluginId;
 | 
				
			||||||
 | 
					        await this.OnChangedLanguage();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private async Task OnChangedLanguage()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (PluginFactory.RunningPlugins.FirstOrDefault(n => n is PluginLanguage && n.Id == this.selectedLanguagePluginId) is not PluginLanguage comparisonPlugin)
 | 
				
			||||||
 | 
					            this.loadingIssue = $"Was not able to load the language plugin for comparison ({this.selectedLanguagePluginId}). Please select a valid, loaded & running language plugin.";
 | 
				
			||||||
 | 
					        else if (comparisonPlugin.IETFTag != this.selectedTargetLanguage.ToIETFTag())
 | 
				
			||||||
 | 
					            this.loadingIssue = $"The selected language plugin for comparison uses the IETF tag '{comparisonPlugin.IETFTag}' which does not match the selected target language '{this.selectedTargetLanguage.ToIETFTag()}'. Please select a valid, loaded & running language plugin which matches the target language.";
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.selectedLanguagePlugin = comparisonPlugin;
 | 
				
			||||||
 | 
					            this.loadingIssue = string.Empty;
 | 
				
			||||||
            await this.LoadData();
 | 
					            await this.LoadData();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        this.StateHasChanged();
 | 
					        this.StateHasChanged();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private async Task LoadData()
 | 
					    private async Task LoadData()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        if (this.selectedLanguagePlugin is null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.loadingIssue = "Please select a language plugin for comparison.";
 | 
				
			||||||
 | 
					            this.localizationPossible = false;
 | 
				
			||||||
 | 
					            this.isLoading = false;
 | 
				
			||||||
 | 
					            this.StateHasChanged();
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        this.isLoading = true;
 | 
					        this.isLoading = true;
 | 
				
			||||||
        this.StateHasChanged();
 | 
					        this.StateHasChanged();
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@ -125,16 +156,11 @@ public partial class AssistantI18N : AssistantBaseCore<SettingsDialogI18N>
 | 
				
			|||||||
                this.loadingIssue = string.Empty;
 | 
					                this.loadingIssue = string.Empty;
 | 
				
			||||||
                var newI18NContent = pluginLanguage.Content;
 | 
					                var newI18NContent = pluginLanguage.Content;
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                if(PluginFactory.RunningPlugins.FirstOrDefault(n => n is PluginLanguage && n.Id == this.selectedLanguagePluginId) is not PluginLanguage comparisonPlugin)
 | 
					                var currentI18NContent = this.selectedLanguagePlugin.Content;
 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    this.loadingIssue = $"Was not able to load the language plugin for comparison ({this.selectedLanguagePluginId}). Please select a valid, loaded & running language plugin.";
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                var currentI18NContent = comparisonPlugin.Content;
 | 
					 | 
				
			||||||
                this.addedKeys = newI18NContent.ExceptBy(currentI18NContent.Keys, n => n.Key).ToDictionary();
 | 
					                this.addedKeys = newI18NContent.ExceptBy(currentI18NContent.Keys, n => n.Key).ToDictionary();
 | 
				
			||||||
                this.removedKeys = currentI18NContent.ExceptBy(newI18NContent.Keys, n => n.Key).ToDictionary();
 | 
					                this.removedKeys = currentI18NContent.ExceptBy(newI18NContent.Keys, n => n.Key).ToDictionary();
 | 
				
			||||||
                this.localizationPossible = true;
 | 
					                this.localizationPossible = true;
 | 
				
			||||||
 | 
					                this.isTranslationNeeded = this.selectedTargetLanguage is not CommonLanguages.EN_US;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user