LanguageInfo.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Globalization;
  2. namespace Abp.Localization
  3. {
  4. /// <summary>
  5. /// Represents an available language for the application.
  6. /// </summary>
  7. public class LanguageInfo
  8. {
  9. /// <summary>
  10. /// Code name of the language.
  11. /// It should be valid culture code.
  12. /// Ex: "en-US" for American English, "tr-TR" for Turkey Turkish.
  13. /// </summary>
  14. public string Name { get; set; }
  15. /// <summary>
  16. /// Display name of the language in it's original language.
  17. /// Ex: "English" for English, "Türkçe" for Turkish.
  18. /// </summary>
  19. public string DisplayName { get; set; }
  20. /// <summary>
  21. /// An icon can be set to display on the UI.
  22. /// </summary>
  23. public string Icon { get; set; }
  24. /// <summary>
  25. /// Is this the default language?
  26. /// </summary>
  27. public bool IsDefault { get; set; }
  28. /// <summary>
  29. /// Is this the language disabled?
  30. /// </summary>
  31. public bool IsDisabled { get; set; }
  32. /// <summary>
  33. /// Is this language Right To Left?
  34. /// </summary>
  35. public bool IsRightToLeft
  36. {
  37. get
  38. {
  39. try
  40. {
  41. return CultureInfo.GetCultureInfo(Name).TextInfo?.IsRightToLeft ?? false;
  42. }
  43. catch
  44. {
  45. return false;
  46. }
  47. }
  48. }
  49. /// <summary>
  50. /// Creates a new <see cref="LanguageInfo"/> object.
  51. /// </summary>
  52. /// <param name="name">
  53. /// Code name of the language.
  54. /// It should be valid culture code.
  55. /// Ex: "en-US" for American English, "tr-TR" for Turkey Turkish.
  56. /// </param>
  57. /// <param name="displayName">
  58. /// Display name of the language in it's original language.
  59. /// Ex: "English" for English, "Türkçe" for Turkish.
  60. /// </param>
  61. /// <param name="icon">An icon can be set to display on the UI</param>
  62. /// <param name="isDefault">Is this the default language?</param>
  63. /// <param name="isDisabled">Is this the language disabled?</param>
  64. public LanguageInfo(string name, string displayName, string icon = null, bool isDefault = false, bool isDisabled = false)
  65. {
  66. Name = name;
  67. DisplayName = displayName;
  68. Icon = icon;
  69. IsDefault = isDefault;
  70. IsDisabled = isDisabled;
  71. }
  72. }
  73. }