Extended the localization system to easily include additional languages in the future

This commit is contained in:
Junior 2023-10-07 00:08:43 -03:00
parent d5ec712d0f
commit ae34584021
50 changed files with 45079 additions and 24129 deletions

View file

@ -67,6 +67,9 @@
SubTitleLabelS2 = new Label();
TitleLabelS2 = new Label();
imageListTips = new ImageList(components);
imageListSendEmailBtn_ko = new ImageList(components);
imageListContinueBtn_ko = new ImageList(components);
imageListOKBtn_ko = new ImageList(components);
Stage1Panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)EmailPictureBox).BeginInit();
((System.ComponentModel.ISupportInitialize)CodePictureBox).BeginInit();
@ -594,6 +597,33 @@
imageListTips.Images.SetKeyName(0, "tips_error.png");
imageListTips.Images.SetKeyName(1, "tips_ok.png");
//
// imageListSendEmailBtn_ko
//
imageListSendEmailBtn_ko.ColorDepth = ColorDepth.Depth32Bit;
imageListSendEmailBtn_ko.ImageStream = (ImageListStreamer)resources.GetObject("imageListSendEmailBtn_ko.ImageStream");
imageListSendEmailBtn_ko.TransparentColor = Color.Transparent;
imageListSendEmailBtn_ko.Images.SetKeyName(0, "ChangePwwnd_button_email_normal_ko.png");
imageListSendEmailBtn_ko.Images.SetKeyName(1, "ChangePwwnd_button_email_active_ko.png");
imageListSendEmailBtn_ko.Images.SetKeyName(2, "ChangePwwnd_button_email_down_ko.png");
//
// imageListContinueBtn_ko
//
imageListContinueBtn_ko.ColorDepth = ColorDepth.Depth32Bit;
imageListContinueBtn_ko.ImageStream = (ImageListStreamer)resources.GetObject("imageListContinueBtn_ko.ImageStream");
imageListContinueBtn_ko.TransparentColor = Color.Transparent;
imageListContinueBtn_ko.Images.SetKeyName(0, "Registerwnd_button_continue_normal_ko.png");
imageListContinueBtn_ko.Images.SetKeyName(1, "Registerwnd_button_continue_active_ko.png");
imageListContinueBtn_ko.Images.SetKeyName(2, "Registerwnd_button_continue_down_ko.png");
//
// imageListOKBtn_ko
//
imageListOKBtn_ko.ColorDepth = ColorDepth.Depth32Bit;
imageListOKBtn_ko.ImageStream = (ImageListStreamer)resources.GetObject("imageListOKBtn_ko.ImageStream");
imageListOKBtn_ko.TransparentColor = Color.Transparent;
imageListOKBtn_ko.Images.SetKeyName(0, "messagewnd.button.ok.normal.png");
imageListOKBtn_ko.Images.SetKeyName(1, "messagewnd.button.ok.active.png");
imageListOKBtn_ko.Images.SetKeyName(2, "messagewnd.button.ok.down.png");
//
// ChangePwd
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -664,5 +694,8 @@
private Label TimerLabel;
private ImageList imageListContinueBtn;
private Label PwdStrengthLabel;
private ImageList imageListSendEmailBtn_ko;
private ImageList imageListContinueBtn_ko;
private ImageList imageListOKBtn_ko;
}
}

View file

@ -12,6 +12,11 @@ namespace RHLauncher
public string SendPasswordCodeUrl = Configuration.Default.SendPasswordCodeUrl;
public string VerifyCodeUrl = Configuration.Default.VerifyCodeUrl;
public string ChangePasswordUrl = Configuration.Default.ChangePasswordUrl;
public string Lang = Configuration.Default.Lang;
private List<Button>? buttons;
private List<ImageList>? imageLists;
private Dictionary<string, List<ImageList>>? languageImageLists;
private readonly System.Windows.Forms.Timer resendTimer = new();
private int secondsLeft = 60;
@ -32,7 +37,9 @@ namespace RHLauncher
resendTimer.Tick += ResendTimer_Tick;
_shouldRestart = shouldRestart;
LoadLocalizedStrings();
Text = LocalizedStrings.RegFormTitle;
TitleLabelS1.Text = LocalizedStrings.ChangePassword;
TitleLabelS2.Text = LocalizedStrings.ChangePassword;
SubTitleLabelS1.Text = LocalizedStrings.RustyHearts;
@ -47,6 +54,24 @@ namespace RHLauncher
}
private void LoadLocalizedStrings()
{
// Initialize buttons and image lists
buttons = new List<Button> { ContinueButtonS1, SendEmailButton, OkButtonS2 };
imageLists = new List<ImageList> { imageListContinueBtn, imageListSendEmailBtn, imageListOKBtn };
// Initialize language-specific image lists
languageImageLists = new Dictionary<string, List<ImageList>>
{
{ "en", new List<ImageList> { imageListContinueBtn, imageListSendEmailBtn, imageListOKBtn } }, // English image lists
{ "ko", new List<ImageList> { imageListContinueBtn_ko, imageListSendEmailBtn_ko, imageListOKBtn_ko } }, // Korean image lists
// Add other languages and their respective image lists here
};
// Load the appropriate resource file based on the selected language
LocalizationHelper.LoadLocalizedStrings(Lang, buttons, imageLists, languageImageLists);
}
#region Methods
private async Task<string> SendEmailRequestAsync()
@ -66,44 +91,44 @@ namespace RHLauncher
Invoke((MethodInvoker)(() =>
{
switch (response)
{
case "EmailSent":
SendEmailButton.Enabled = false;
resendTimer.Start();
break;
case "ValidVerificationCode":
// Hide the firs panel and show the second panel
Stage1Panel.Visible = false;
Stage2Panel.Visible = true;
EmailLabelS2.Text = EmailTextBox.Text;
CodeDescLabel.Text = "";
CodePictureBox.Image = imageListTips.Images[1];
break;
case "PasswordChanged":
MsgBoxForm.Show(LocalizedStrings.PasswordChanged, LocalizedStrings.Success);
OnPasswordChanged();
break;
case "SamePassword":
MsgBoxForm.Show(LocalizedStrings.SamePassword, LocalizedStrings.Failed);
break;
case "AccountNotFound":
EmailDescLabel.Text = LocalizedStrings.AccountNotFound;
EmailDescLabel.ForeColor = Color.Red;
EmailPictureBox.Image = imageListTips.Images[0];
return;
case "InvalidVerificationCode":
CodeDescLabel.Text = LocalizedStrings.InvalidVerificationCode;
CodeDescLabel.ForeColor = Color.Red;
CodePictureBox.Image = imageListTips.Images[0];
return;
case "ExpiredVerificationCode":
CodeDescLabel.Text = LocalizedStrings.ExpiredVerificationCode;
CodeDescLabel.ForeColor = Color.Red;
CodePictureBox.Image = imageListTips.Images[0];
return;
default:
MsgBoxForm.Show("Error:" + response, LocalizedStrings.Error);
break;
{
case "EmailSent":
SendEmailButton.Enabled = false;
resendTimer.Start();
break;
case "ValidVerificationCode":
// Hide the firs panel and show the second panel
Stage1Panel.Visible = false;
Stage2Panel.Visible = true;
EmailLabelS2.Text = EmailTextBox.Text;
CodeDescLabel.Text = "";
CodePictureBox.Image = imageListTips.Images[1];
break;
case "PasswordChanged":
MsgBoxForm.Show(LocalizedStrings.PasswordChanged, LocalizedStrings.Success);
OnPasswordChanged();
break;
case "SamePassword":
MsgBoxForm.Show(LocalizedStrings.SamePassword, LocalizedStrings.Failed);
break;
case "AccountNotFound":
EmailDescLabel.Text = LocalizedStrings.AccountNotFound;
EmailDescLabel.ForeColor = Color.Red;
EmailPictureBox.Image = imageListTips.Images[0];
return;
case "InvalidVerificationCode":
CodeDescLabel.Text = LocalizedStrings.InvalidVerificationCode;
CodeDescLabel.ForeColor = Color.Red;
CodePictureBox.Image = imageListTips.Images[0];
return;
case "ExpiredVerificationCode":
CodeDescLabel.Text = LocalizedStrings.ExpiredVerificationCode;
CodeDescLabel.ForeColor = Color.Red;
CodePictureBox.Image = imageListTips.Images[0];
return;
default:
MsgBoxForm.Show("Error:" + response, LocalizedStrings.Error);
break;
}
}));
}

File diff suppressed because it is too large Load diff