35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using Processor;
|
|
|
|
namespace UI_WinForms.Components;
|
|
|
|
public partial class Translations : UserControl
|
|
{
|
|
private readonly Dictionary<string, Translation> translationComponents = new();
|
|
|
|
public Translations()
|
|
{
|
|
this.InitializeComponent();
|
|
this.Load += async (sender, args) => await this.SetupTranslations();
|
|
AppEvents.WhenTextElementChanged += async (sender, textElement) =>
|
|
{
|
|
var allTranslations = await TranslationProcessor.GetTranslations(textElement);
|
|
foreach (var translation in allTranslations)
|
|
if (this.translationComponents.ContainsKey(translation.Culture))
|
|
this.translationComponents[translation.Culture].Configure(translation);
|
|
};
|
|
}
|
|
|
|
private async Task SetupTranslations()
|
|
{
|
|
if(this.DesignMode)
|
|
return;
|
|
|
|
var cultureInfos = await AppSettings.GetCultureInfos();
|
|
foreach (var cultureInfo in cultureInfos.OrderByDescending(n => n.Index))
|
|
{
|
|
var translationComponent = new Translation(cultureInfo.Code);
|
|
this.translationComponents.Add(cultureInfo.Code, translationComponent);
|
|
this.panelTranslations.Controls.Add(translationComponent);
|
|
}
|
|
}
|
|
} |