Changeset 1591
- Timestamp:
- 1/19/2010 2:49:02 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/Localisation.cs
r1485 r1591 45 45 /// <param name="str">The string to localise.</param> 46 46 /// <returns>A localised string, or str if no localisation exists.</returns> 47 public static string _(string str)48 { 49 return TranslateText( str, Assembly.GetCallingAssembly());50 } 51 52 /// <summary> 53 /// Translates the localisable string to the localised string, formatting all47 public static string _(string text) 48 { 49 return TranslateText(text, Assembly.GetCallingAssembly()); 50 } 51 52 /// <summary> 53 /// Translates the localisable text to the localised text, formatting all 54 54 /// placeholders using composite formatting. This is shorthand for 55 /// <code>string.Format(S._( str), args)</code>56 /// </summary> 57 /// <param name=" str">The stringto localise.</param>55 /// <code>string.Format(S._(text), args)</code> 56 /// </summary> 57 /// <param name="text">The text to localise.</param> 58 58 /// <param name="args">Arguments for the composite formatting call.</param> 59 59 /// <returns>The formatted and localised string.</returns> 60 60 /// <remarks>The localised string is retrieved before formatting.</remarks> 61 public static string _(string str, params object[] args)61 public static string _(string text, params object[] args) 62 62 { 63 63 //Get the localised version of the input string. 64 string localStr = TranslateText( str, Assembly.GetCallingAssembly());64 string localStr = TranslateText(text, Assembly.GetCallingAssembly()); 65 65 66 66 //Format the string. … … 76 76 { 77 77 if (control == null) 78 return CultureInfo.CurrentCulture.TextInfo.IsRightToLeft;78 throw new ArgumentNullException("control"); 79 79 80 80 switch (control.RightToLeft) … … 92 92 /// Translates the localisable string to the set localised string. 93 93 /// </summary> 94 /// <param name=" str">The string to localise.</param>94 /// <param name="text">The string to localise.</param> 95 95 /// <param name="assembly">The assembly from which localised resource satellite 96 96 /// assemblies should be loaded from.</param> 97 97 /// <returns>A localised string, or str if no localisation exists.</returns> 98 public static string TranslateText(string str, Assembly assembly)98 public static string TranslateText(string text, Assembly assembly) 99 99 { 100 100 //If the string is empty, forget it! 101 if ( str.Length == 0)102 return str;101 if (text.Length == 0) 102 return text; 103 103 104 104 //First get the dictionary mapping assemblies and ResourceManagers (i.e. pick out … … 132 132 res = assemblies[assembly]; 133 133 134 string result = res.GetString(Escape( str), Thread.CurrentThread.CurrentUICulture);134 string result = res.GetString(Escape(text), Thread.CurrentThread.CurrentUICulture); 135 135 #if DEBUG 136 return string.IsNullOrEmpty(result) ? str: Unescape(result);136 return string.IsNullOrEmpty(result) ? text : Unescape(result); 137 137 #else 138 return string.IsNullOrEmpty(result) || result == "(Untranslated)" ? str: Unescape(result);138 return string.IsNullOrEmpty(result) || result == "(Untranslated)" ? text : Unescape(result); 139 139 #endif 140 140 }
Note: See TracChangeset
for help on using the changeset viewer.
