Skip to content

Commit eededfd

Browse files
author
Kabuto_W
committed
Improve localization.
1 parent f6d1225 commit eededfd

File tree

10 files changed

+720
-200
lines changed

10 files changed

+720
-200
lines changed

SimilarImages/SimilarImages/Form1.Designer.cs

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SimilarImages/SimilarImages/Form1.cs

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public partial class Form1 : Form
2020

2121
private List<string> folderPathes = new List<string>();
2222
private List<Tuple<string, string, double>> tuples = null;
23-
private readonly bool isSimplifiedChinese = CultureInfo.CurrentUICulture.Name == "zh-CN";
2423

2524
public Form1()
2625
{
26+
CultureInfo.CurrentUICulture = new CultureInfo("zh-CN");
2727
InitializeComponent();
28-
toolTip1.ToolTipTitle = isSimplifiedChinese ? "帮助" : "Help";
28+
toolTip1.ToolTipTitle = Message.Help;
2929
}
3030

3131
private void Form1_SizeChanged(object sender, EventArgs e)
@@ -41,13 +41,13 @@ private void Form1_Load(object sender, EventArgs e)
4141
tkb_Threshold.Value = 80;
4242
cmb_Algorithm.SelectedIndex = 0;
4343
cmb_Interpolation.SelectedIndex = 0;
44-
tb_Directory.Text = null;
44+
tb_Directory.Text = Message.DragHere;
4545
}
4646

4747
private void btn_Clear_Click(object sender, EventArgs e)
4848
{
4949
folderPathes.Clear();
50-
tb_Directory.Text = null;
50+
tb_Directory.Text = Message.DragHere;
5151
ClearResult();
5252
}
5353

@@ -67,9 +67,7 @@ private void Form1_DragEnter(object sender, DragEventArgs e)
6767
}
6868

6969
e.Effect = DragDropEffects.None;
70-
MessageBox.Show(
71-
isSimplifiedChinese ? "仅支持文件夹。" : "Support folder(s) only.",
72-
isSimplifiedChinese ? "提示" : "Notice",
70+
MessageBox.Show(Message.FolderOnly, Message.Notice,
7371
MessageBoxButtons.OK, MessageBoxIcon.Warning);
7472
}
7573

@@ -89,16 +87,8 @@ private void tkb_Precision_ValueChanged(object sender, EventArgs e)
8987

9088
private void tkb_Precision_MouseHover(object sender, EventArgs e)
9189
{
92-
string tip = "Current Value: " + tkb_Precision.Value + "\n" +
93-
"Usage: When sampling, resize images to \"Precision * Precision\".\n" +
94-
"Notice: Don't set it too large to run out of memory.\n";
95-
if (isSimplifiedChinese)
96-
{
97-
tip = "当前值:" + tkb_Precision.Value + "\n" +
98-
"用途:采样时将图片缩放至 “精度 * 精度”。\n" +
99-
"注意:不要设置得太大以免耗尽内存。\n";
100-
}
101-
toolTip1.SetToolTip((Control)sender, tip);
90+
toolTip1.SetToolTip((Control)sender,
91+
Message.CurrentValue + tkb_Precision.Value + Message.PresionHelp);
10292
}
10393

10494
private void cmb_Interpolation_SelectedIndexChanged(object sender, EventArgs e)
@@ -115,12 +105,7 @@ private void cmb_Interpolation_SelectedIndexChanged(object sender, EventArgs e)
115105

116106
private void cmb_Interpolation_MouseHover(object sender, EventArgs e)
117107
{
118-
string tip = "The interpolation mode when resizing images.";
119-
if (isSimplifiedChinese)
120-
{
121-
tip = "图片缩放时的插值模式。";
122-
}
123-
toolTip1.SetToolTip((Control)sender, tip);
108+
toolTip1.SetToolTip((Control)sender, Message.InterpolationHelp);
124109
}
125110

126111
private void cmb_Algorithm_SelectedIndexChanged(object sender, EventArgs e)
@@ -130,12 +115,7 @@ private void cmb_Algorithm_SelectedIndexChanged(object sender, EventArgs e)
130115

131116
private void cmb_Algorithm_MouseHover(object sender, EventArgs e)
132117
{
133-
string tip = "The algorithm when calculating image hashes.";
134-
if (isSimplifiedChinese)
135-
{
136-
tip = "计算图片哈希时使用的算法。";
137-
}
138-
toolTip1.SetToolTip((Control)sender, tip);
118+
toolTip1.SetToolTip((Control)sender, Message.AlgorithmHelp);
139119
}
140120

141121
private void tkb_Threshold_ValueChanged(object sender, EventArgs e)
@@ -145,19 +125,8 @@ private void tkb_Threshold_ValueChanged(object sender, EventArgs e)
145125

146126
private void tkb_Threshold_MouseHover(object sender, EventArgs e)
147127
{
148-
string tip = "Current Value: " + tkb_Threshold.Value + "%\n" +
149-
"Range: 0-99%.\n" +
150-
"Usage: Return results greater than the threshold.\n" +
151-
"Notice: Don't set a low threshold when processing mass images, " +
152-
"as the operation will take too long.";
153-
if (isSimplifiedChinese)
154-
{
155-
tip = "当前值:" + tkb_Threshold.Value + "%\n" +
156-
"范围:0-99%。\n" +
157-
"用途:返回大于阈值的结果。\n" +
158-
"注意:当图片数量较多时,不要使用低阈值,以免耗时太长。\n";
159-
}
160-
toolTip1.SetToolTip((Control)sender, tip);
128+
toolTip1.SetToolTip((Control)sender,
129+
Message.CurrentValue + tkb_Threshold.Value + Message.ThresholdHelp);
161130
}
162131

163132
#endregion Config
@@ -169,12 +138,15 @@ private void btn_Process_Click(object sender, EventArgs e)
169138
// Check config
170139
precision = tkb_Precision.Value;
171140
threshold = tkb_Threshold.Value;
172-
if (folderPathes.Count == 0 ||
173-
!folderPathes.TrueForAll((path) => Directory.Exists(path)))
141+
if (folderPathes.Count == 0)
142+
{
143+
MessageBox.Show(Message.NoFolder, Message.Notice,
144+
MessageBoxButtons.OK, MessageBoxIcon.Information);
145+
return;
146+
}
147+
if (!folderPathes.TrueForAll((path) => Directory.Exists(path)))
174148
{
175-
MessageBox.Show(
176-
isSimplifiedChinese ? "文件夹不存在。" : "Directory does not exist.",
177-
isSimplifiedChinese ? "提示" : "Notice",
149+
MessageBox.Show(Message.FolderNotExist, Message.Notice,
178150
MessageBoxButtons.OK, MessageBoxIcon.Information);
179151
return;
180152
}
@@ -193,12 +165,12 @@ private void ClearResult()
193165
lvw_Result.Items.Clear();
194166
pictureBox1.Image?.Dispose();
195167
pictureBox1.Image = null;
196-
lb_Image1.Text = isSimplifiedChinese ? "图片 1" : "Image 1";
168+
lb_Image1.Text = Message.Image1;
197169
lb_Image1.Tag = null;
198170
lb_Resolution1.Text = null;
199171
pictureBox2.Image?.Dispose();
200172
pictureBox2.Image = null;
201-
lb_Image2.Text = isSimplifiedChinese ? "图片 2" : "Image 2";
173+
lb_Image2.Text = Message.Image2;
202174
lb_Image2.Tag = null;
203175
lb_Resolution2.Text = null;
204176
}
@@ -223,15 +195,15 @@ private void bgw_Calculate_RunWorkerCompleted(object sender, RunWorkerCompletedE
223195
btn_Process.Enabled = true;
224196
if (tuples == null || tuples.Count == 0)
225197
{
226-
lvw_Result.Items.Add("No result");
198+
lvw_Result.Items.Add(Message.NoResult);
227199
return;
228200
}
229201

230202
// Generate result list
231203
lvw_Result.BeginUpdate();
232204
for (int i = 0; i < tuples.Count; i++)
233205
{
234-
lvw_Result.Items.Add($"Result {i + 1} - {tuples[i].Item3:P1}");
206+
lvw_Result.Items.Add($"{Message.Result} {i + 1} - {tuples[i].Item3:P1}");
235207
}
236208
lvw_Result.EndUpdate();
237209
if (lvw_Result.Items.Count > 0)
@@ -248,7 +220,7 @@ private void bgw_Calculate_RunWorkerCompleted(object sender, RunWorkerCompletedE
248220
private void lvw_Result_SelectedIndexChanged(object sender, EventArgs e)
249221
{
250222
if (lvw_Result.SelectedItems.Count < 1 ||
251-
lvw_Result.SelectedItems[0].Text == "No result")
223+
lvw_Result.SelectedItems[0].Text == Message.NoResult)
252224
{ return; }
253225

254226
// Dispose previous images
@@ -267,7 +239,7 @@ private void lvw_Result_SelectedIndexChanged(object sender, EventArgs e)
267239
catch (ArgumentException)
268240
{
269241
pictureBox1.Image = null;
270-
lb_Image1.Text = "Deleted";
242+
lb_Image1.Text = Message.Deleted;
271243
lb_Image1.Tag = null;
272244
lb_Resolution1.Text = null;
273245
}
@@ -281,7 +253,7 @@ private void lvw_Result_SelectedIndexChanged(object sender, EventArgs e)
281253
catch (ArgumentException)
282254
{
283255
pictureBox2.Image = null;
284-
lb_Image2.Text = "Deleted";
256+
lb_Image2.Text = Message.Deleted;
285257
lb_Image2.Tag = null;
286258
lb_Resolution2.Text = null;
287259
}
@@ -313,15 +285,16 @@ private void DeleteImage(PictureBox pictureBox, Label label)
313285
{
314286
if (pictureBox.Image == null) { return; }
315287

316-
DialogResult dr = MessageBox.Show($"Move this image [{label.Text}] to recycle bin?",
317-
"Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
288+
DialogResult dr = MessageBox.Show(
289+
Message.DeleteImage_1 + label.Text + Message.DeleteImage_2,
290+
Message.Confirm, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
318291
if (dr == DialogResult.OK)
319292
{
320293
pictureBox.Image.Dispose();
321294
pictureBox.Image = null;
322295
FileSystem.DeleteFile(label.Tag.ToString(),
323296
UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
324-
label.Text = "Deleted";
297+
label.Text = Message.Deleted;
325298
}
326299
}
327300

0 commit comments

Comments
 (0)