changeset 36:c949727ec0e0

Re #22 - Make failing control translation cleaner for normal use * Add extra Translate method for ITranslatables that takes a default text string
author IBBoard <dev@ibboard.co.uk>
date Tue, 19 May 2009 19:55:21 +0000
parents 2b5e73cb83a3
children cc7fae81afec
files Lang/Translation.cs
diffstat 1 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Lang/Translation.cs	Tue May 19 19:35:34 2009 +0000
+++ b/Lang/Translation.cs	Tue May 19 19:55:21 2009 +0000
@@ -331,7 +331,8 @@
 		}
 
 		/// <summary>
-		/// Translate an <see cref="ITranslatable"/> item, with optional string replacement
+		/// Translate an <see cref="ITranslatable"/> item, with optional string replacement. If the translation
+		/// does not exist then a warning message will be used as the translated text.
 		/// </summary>
 		/// <param name="item">
 		/// A <see cref="ITranslatable"/> to set the text for
@@ -341,13 +342,32 @@
 		/// </param>
 		public static void Translate(ITranslatable item, params object[] replacements)
 		{
+			Translate(item, (string)null, replacements);
+		}
+
+		/// <summary>
+		/// Translate an <see cref="ITranslatable"/> item, with optional string replacement. The <code>defaultText</code>
+		/// can be used to specify an alternate translation. Passing <code>null</code> will result in a warning message
+		/// about a missing translation ID.
+		/// </summary>
+		/// <param name="item">
+		/// A <see cref="ITranslatable"/> to set the text for
+		/// </param>
+		/// <param name="defaultText">
+		/// The default string to display if no translation could be found.
+		/// </param>
+		/// <param name="replacements">
+		/// A collection of <see cref="System.Object"/>s that will be used to fill place-holders
+		/// </param>
+		public static void Translate(ITranslatable item, string defaultText, params object[] replacements)
+		{
 			if (item.Text == "" || item.Text == DIVIDER_STRING)
 			{
 				//it doesn't need translating - either there is no text from the developer or it's a hyphen for a divider
 				return;
 			}
-			
-			item.Text = GetTranslation(item.Name, replacements);
+
+			item.Text = GetTranslation(item.Name, defaultText, replacements);
 		}
 		
 		/// <summary>