This commit is contained in:
122
source/WinFormApp/LocalizeHelperForm.cs
Normal file
122
source/WinFormApp/LocalizeHelperForm.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using GZTW.AyaNova.BLL;
|
||||
|
||||
namespace AyaNova
|
||||
{
|
||||
public partial class LocalizeHelperForm : Form
|
||||
{
|
||||
|
||||
private string CurrentLocale = string.Empty;
|
||||
private List<LocalizeHelperItem> listItems = null;
|
||||
|
||||
public LocalizeHelperForm(List<string> SelectedLocaleKeys)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
CurrentLocale = User.CurrentUserLanguage;
|
||||
List<LocalizeHelperItem> rawItems = new List<LocalizeHelperItem>(SelectedLocaleKeys.Count);
|
||||
foreach (string s in SelectedLocaleKeys)
|
||||
rawItems.Add(new LocalizeHelperItem(s));
|
||||
|
||||
listItems = rawItems.OrderBy(si => si.current).ToList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void LocalizeHelperForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
this.helpProvider1.HelpNamespace = Util.BaseHelpUrl + "customize_text.htm";
|
||||
this.Icon = Resource1.Localization16icon;
|
||||
this.Text = Util.LocaleText.GetLocalizedText("O.Locale") + ": " + User.CurrentUserLanguage;
|
||||
grid.DataSource = listItems;
|
||||
grid.Columns["previous"].DefaultCellStyle.ForeColor = SystemColors.GrayText;
|
||||
grid.ColumnHeadersVisible = false;
|
||||
if (CurrentLocale == "English")
|
||||
{
|
||||
Util.PromptWithIconOKOnlyFromLocaleKey("Locale.Label.WarnLocaleLocked", MessageBoxIcon.Hand);
|
||||
grid.ReadOnly = true;
|
||||
btnOK.Enabled = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public class LocalizeHelperItem
|
||||
{
|
||||
[Browsable(false)]
|
||||
public string key { get; set; }
|
||||
|
||||
[ReadOnly(true)]
|
||||
public string previous { get; set; }
|
||||
|
||||
public string current { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public bool IsChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
return previous != current;
|
||||
}
|
||||
}
|
||||
|
||||
public LocalizeHelperItem(string Key)
|
||||
{
|
||||
key = Key;
|
||||
previous = current = Util.LocaleText.GetLocalizedText(Key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
//save changes if any
|
||||
bool hasChanges = false;
|
||||
foreach (LocalizeHelperItem i in listItems)
|
||||
{
|
||||
if (i.IsChanged)
|
||||
{
|
||||
hasChanges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasChanges)
|
||||
{
|
||||
LocalizedTexts t = LocalizedTexts.GetItemsForLocale(CurrentLocale);
|
||||
foreach (LocalizeHelperItem i in listItems)
|
||||
{
|
||||
if (i.IsChanged)
|
||||
{
|
||||
foreach (LocalizedText lt in t)
|
||||
{
|
||||
if (lt.Key == i.key)
|
||||
{
|
||||
lt.DisplayText = i.current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Save();
|
||||
Util.LocaleText = LocalizedTextTable.Load(CurrentLocale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
|
||||
}//ens
|
||||
Reference in New Issue
Block a user