Advertisement
Guest User

UserMessage

a guest
Jun 12th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1.  public static class UserMessage
  2.     {
  3.         private static ResourceManager _resourceManager;
  4.  
  5.         static UserMessage()
  6.         {
  7.             string baseName = Assembly.GetAssembly(typeof(UserMessage)).GetName().Name + ".Messages.de";
  8.             Console.WriteLine(baseName);
  9.             _resourceManager = new ResourceManager(baseName, Properties.GlobalizationAssembly);
  10.         }
  11.  
  12.         public static string GetMessage(string msgID, params string[] arguments)
  13.         {
  14.             string msg = "";
  15.             string error = "[Message Error] cannot read Message " + msgID;
  16.             try
  17.             {
  18.                 msg = _resourceManager.GetString(msgID, new CultureInfo(Properties.DefaultLanguage));
  19.  
  20.                 for (int i = 0; i < arguments.Length; i++)
  21.                 {
  22.                     msg = msg.Replace("{" + i.ToString() + "}", arguments[i]);
  23.                 }
  24.             }
  25.             catch (Exception ex)
  26.             {
  27.                 Console.WriteLine(error + "\r\n" + ex.ToString());
  28.                 return error;
  29.             }
  30.             return msg;
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement