Mercurial > repos > IBBoard.Windows.Forms
comparison Windows/Forms/I18N/ControlTranslator.cs @ 2:b829a3320688
Re #3 - Copy control related translation to new class in I18N
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Dec 2008 18:33:01 +0000 |
parents | |
children | 1acdb0aff4a7 |
comparison
equal
deleted
inserted
replaced
1:258ef411e698 | 2:b829a3320688 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Text; | |
4 using System.Windows.Forms; | |
5 using System.ComponentModel; | |
6 using IBBoard.Lang; | |
7 | |
8 namespace IBBoard.Windows.Forms.I18N | |
9 { | |
10 public class ControlTranslator | |
11 { | |
12 public static void TranslateControl(Control ctrl, params object[] replacements) | |
13 { | |
14 TranslateControl(ctrl, true, replacements); | |
15 } | |
16 | |
17 public static void TranslateControl(Control ctrl, bool cascadeTranslate, params object[] replacements) | |
18 { | |
19 if (ctrl is ITranslatable) | |
20 { | |
21 Translation.Translate((ITranslatable)ctrl, replacements); | |
22 } | |
23 | |
24 if (cascadeTranslate) | |
25 { | |
26 CascadeControlTranslation(ctrl, replacements); | |
27 } | |
28 } | |
29 | |
30 private static void CascadeControlTranslation(Control ctrl, params object[] replacements) | |
31 { | |
32 if (ctrl is ToolBar) | |
33 { | |
34 foreach (ToolBarButton bttn in ((ToolBar)ctrl).Buttons) | |
35 { | |
36 TranslateComponent(bttn, true, replacements); | |
37 } | |
38 } | |
39 else | |
40 { | |
41 foreach (Control subctr in ctrl.Controls) | |
42 { | |
43 TranslateControl(subctr, true, replacements); | |
44 } | |
45 } | |
46 } | |
47 | |
48 public static void TranslateComponent(Component comp, params object[] replacements) | |
49 { | |
50 TranslateComponent(comp, true, replacements); | |
51 } | |
52 | |
53 public static void TranslateComponent(Component comp, bool cascadeTranslate, params object[] replacements) | |
54 { | |
55 if (comp is ITranslatable) | |
56 { | |
57 Translation.Translate((ITranslatable)comp, replacements); | |
58 } | |
59 else if (comp is FileDialog) | |
60 { | |
61 //HACK: We can't override SWF dialogs in .Net 1.1, so put in a special condition check for them | |
62 FileDialog dialog = (FileDialog)comp; | |
63 | |
64 if (dialog.Title.StartsWith("Translatable:")) | |
65 { | |
66 dialog.Title = Translation.GetTranslation(dialog.Title.Substring(13), replacements); | |
67 } | |
68 } | |
69 | |
70 if (cascadeTranslate) | |
71 { | |
72 CascadeComponentTranslations(comp, cascadeTranslate, replacements); | |
73 } | |
74 } | |
75 | |
76 private static void CascadeComponentTranslations(Component comp, params object[] replacements) | |
77 { | |
78 if (comp is Menu) | |
79 { | |
80 foreach (MenuItem mi in ((Menu)comp).MenuItems) | |
81 { | |
82 TranslateComponent(mi, true, replacements); | |
83 } | |
84 } | |
85 } | |
86 } | |
87 } |