You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1 KiB

1 year ago
  1. using Newtonsoft.Json;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.IO;
  5. namespace Common.Language
  6. {
  7. /// <summary>
  8. /// </summary>
  9. public static class Languages
  10. {
  11. /// <summary>
  12. /// </summary>
  13. /// <param name="key"></param>
  14. /// <param name="lang"></param>
  15. /// <returns></returns>
  16. public static string GetMessage(string key, string lang)
  17. {
  18. string text = null;
  19. var path = (ConfigurationManager.AppSettings["PushNotification_Resource"]).ToString();
  20. //if (string.IsNullOrEmpty(lang))
  21. //{
  22. // text = File.ReadAllText(path+"PushNotification_en.json");
  23. //}
  24. //else {
  25. // text = File.ReadAllText(path+"PushNotification_"+lang+ ".json");
  26. //}
  27. text = File.ReadAllText(path + "PushNotification_en.json");
  28. if (!string.IsNullOrEmpty(text))
  29. {
  30. var msg = key;
  31. var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
  32. dic.TryGetValue(key, out msg);
  33. return msg;
  34. }
  35. return key;
  36. }
  37. public static string GetTitle(string key, string lang)
  38. {
  39. string text = null;
  40. var path = (ConfigurationManager.AppSettings["PushNotification_Resource"]).ToString();
  41. //if (string.IsNullOrEmpty(lang))
  42. //{
  43. // text = File.ReadAllText(path + "PushNotification_Title_en.json");
  44. //}
  45. //else
  46. //{
  47. // text = File.ReadAllText(path + "PushNotification_Title_" + lang + ".json");
  48. //}
  49. text = File.ReadAllText(path + "PushNotification_Title_en.json");
  50. if (!string.IsNullOrEmpty(text))
  51. {
  52. var msg = key;
  53. var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
  54. dic.TryGetValue(key, out msg);
  55. return msg;
  56. }
  57. return key;
  58. }
  59. }
  60. }