changeset 6:97cab866aba9

Re #22 - Make failing control translation cleaner for normal use * Use new translation method with default text parameter and pass current text as default Also: * Cleanup control translator tabbing
author IBBoard <dev@ibboard.co.uk>
date Mon, 25 May 2009 10:29:21 +0000
parents c70356dc5609
children 02a7c7aaf2c1
files Windows/Forms/I18N/ControlTranslator.cs
diffstat 1 files changed, 76 insertions(+), 70 deletions(-) [+]
line diff
     1.1 --- a/Windows/Forms/I18N/ControlTranslator.cs	Mon May 25 10:27:46 2009 +0000
     1.2 +++ b/Windows/Forms/I18N/ControlTranslator.cs	Mon May 25 10:29:21 2009 +0000
     1.3 @@ -11,81 +11,87 @@
     1.4  
     1.5  namespace IBBoard.Windows.Forms.I18N
     1.6  {
     1.7 -    public class ControlTranslator
     1.8 -    {
     1.9 -        public static void TranslateControl(Control ctrl, params object[] replacements)
    1.10 -        {
    1.11 -            TranslateControl(ctrl, true, replacements);
    1.12 -        }
    1.13 +	public class ControlTranslator
    1.14 +	{
    1.15 +		public static void TranslateControl(Control ctrl, params object[] replacements)
    1.16 +		{
    1.17 +			TranslateControl(ctrl, true, replacements);
    1.18 +		}
    1.19  
    1.20 -        public static void TranslateControl(Control ctrl, bool cascadeTranslate, params object[] replacements)
    1.21 -        {
    1.22 -            if (ctrl is ITranslatable)
    1.23 -            {
    1.24 -                Translation.Translate((ITranslatable)ctrl, replacements);
    1.25 -            }
    1.26 +		public static void TranslateControl(Control ctrl, bool cascadeTranslate, params object[] replacements)
    1.27 +		{
    1.28 +			if (ctrl is ITranslatable)
    1.29 +			{
    1.30 +				Translate((ITranslatable)ctrl, replacements);
    1.31 +			}
    1.32  
    1.33 -            if (cascadeTranslate)
    1.34 -            {
    1.35 -                CascadeControlTranslation(ctrl, replacements);
    1.36 -            }
    1.37 -        }
    1.38 +			if (cascadeTranslate)
    1.39 +			{
    1.40 +				CascadeControlTranslation(ctrl, replacements);
    1.41 +			}
    1.42 +		}
    1.43  
    1.44 -        private static void CascadeControlTranslation(Control ctrl, params object[] replacements)
    1.45 -        {
    1.46 -            if (ctrl is ToolBar)
    1.47 -            {
    1.48 -                foreach (ToolBarButton bttn in ((ToolBar)ctrl).Buttons)
    1.49 -                {
    1.50 -                    TranslateComponent(bttn, true, replacements);
    1.51 -                }
    1.52 -            }
    1.53 -            else
    1.54 -            {
    1.55 -                foreach (Control subctr in ctrl.Controls)
    1.56 -                {
    1.57 -                    TranslateControl(subctr, true, replacements);
    1.58 -                }
    1.59 -            }
    1.60 -        }
    1.61 +		private static void Translate(ITranslatable translatable, params object[] replacements)
    1.62 +		{
    1.63 +			Translation.Translate(translatable, translatable.Text, replacements);
    1.64 +		}
    1.65  
    1.66 -        public static void TranslateComponent(Component comp, params object[] replacements)
    1.67 -        {
    1.68 -            TranslateComponent(comp, true, replacements);
    1.69 -        }
    1.70 +		private static void CascadeControlTranslation(Control ctrl, params object[] replacements)
    1.71 +		{
    1.72 +			if (ctrl is ToolBar)
    1.73 +			{
    1.74 +				foreach (ToolBarButton bttn in ((ToolBar)ctrl).Buttons)
    1.75 +				{
    1.76 +					TranslateComponent(bttn, true, replacements);
    1.77 +				}
    1.78 +			}
    1.79 +			else
    1.80 +			{
    1.81 +				foreach (Control subctr in ctrl.Controls)
    1.82 +				{
    1.83 +					TranslateControl(subctr, true, replacements);
    1.84 +				}
    1.85 +			}
    1.86 +		}
    1.87  
    1.88 -        public static void TranslateComponent(Component comp, bool cascadeTranslate, params object[] replacements)
    1.89 -        {
    1.90 -            if (comp is ITranslatable)
    1.91 -            {
    1.92 -                Translation.Translate((ITranslatable)comp, replacements);
    1.93 -            }
    1.94 -            else if (comp is FileDialog)
    1.95 -            {
    1.96 -                //HACK: We can't override SWF dialogs in .Net 1.1, so put in a special condition check for them
    1.97 -                FileDialog dialog = (FileDialog)comp;
    1.98 +		public static void TranslateComponent(Component comp, params object[] replacements)
    1.99 +		{
   1.100 +			TranslateComponent(comp, true, replacements);
   1.101 +		}
   1.102  
   1.103 -                if (dialog.Title.StartsWith("Translatable:"))
   1.104 -                {
   1.105 -                    dialog.Title = Translation.GetTranslation(dialog.Title.Substring(13), replacements);
   1.106 -                }
   1.107 -            }
   1.108 +		public static void TranslateComponent(Component comp, bool cascadeTranslate, params object[] replacements)
   1.109 +		{
   1.110 +			if (comp is ITranslatable)
   1.111 +			{
   1.112 +				Translate((ITranslatable)comp, replacements);
   1.113 +			}
   1.114 +			else if (comp is FileDialog)
   1.115 +			{
   1.116 +				//HACK: We can't override SWF dialogs in .Net 1.1, so put in a special condition check for them
   1.117 +				FileDialog dialog = (FileDialog)comp;
   1.118  
   1.119 -            if (cascadeTranslate)
   1.120 -            {
   1.121 -                CascadeComponentTranslations(comp, cascadeTranslate, replacements);
   1.122 -            }
   1.123 -        }
   1.124 +				if (dialog.Title.StartsWith("Translatable:"))
   1.125 +				{
   1.126 +					string title = dialog.Title.Substring(13);
   1.127 +					dialog.Title = Translation.GetTranslation(title, title, replacements);
   1.128 +				}
   1.129 +			}
   1.130  
   1.131 -        private static void CascadeComponentTranslations(Component comp, params object[] replacements)
   1.132 -        {
   1.133 -            if (comp is Menu)
   1.134 -            {
   1.135 -                foreach (MenuItem mi in ((Menu)comp).MenuItems)
   1.136 -                {
   1.137 -                    TranslateComponent(mi, true, replacements);
   1.138 -                }
   1.139 -            }
   1.140 -        }
   1.141 -    }
   1.142 -}
   1.143 +			if (cascadeTranslate)
   1.144 +			{
   1.145 +				CascadeComponentTranslations(comp, cascadeTranslate, replacements);
   1.146 +			}
   1.147 +		}
   1.148 +
   1.149 +		private static void CascadeComponentTranslations(Component comp, params object[] replacements)
   1.150 +		{
   1.151 +			if (comp is Menu)
   1.152 +			{
   1.153 +				foreach (MenuItem mi in ((Menu)comp).MenuItems)
   1.154 +				{
   1.155 +					TranslateComponent(mi, true, replacements);
   1.156 +				}
   1.157 +			}
   1.158 +		}
   1.159 +	}
   1.160 +}
   1.161 \ No newline at end of file