GlobalResources.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #nullable enable
  2. using System.Collections;
  3. using System.Globalization;
  4. using System.Resources;
  5. namespace Terminal.Gui.Resources;
  6. /// <summary>
  7. /// Provide static access to the ResourceManagerWrapper
  8. /// </summary>
  9. public static class GlobalResources
  10. {
  11. private static readonly ResourceManagerWrapper _resourceManagerWrapper;
  12. static GlobalResources ()
  13. {
  14. // Initialize the ResourceManagerWrapper once
  15. var resourceManager = new ResourceManager (typeof (Strings));
  16. _resourceManagerWrapper = new (resourceManager);
  17. }
  18. /// <summary>
  19. /// Looks up a resource value for a particular name. Looks in the specified CultureInfo, and if not found, all parent
  20. /// CultureInfos.
  21. /// </summary>
  22. /// <param name="name"></param>
  23. /// <param name="culture"></param>
  24. /// <returns>Null if the resource was not found in the current culture or the invariant culture.</returns>
  25. public static object GetObject (string name, CultureInfo culture = null!) { return _resourceManagerWrapper.GetObject (name, culture); }
  26. /// <summary>
  27. /// Looks up a set of resources for a particular CultureInfo. This is not useful for most users of the ResourceManager
  28. /// - call GetString() or GetObject() instead. The parameters let you control whether the ResourceSet is created if it
  29. /// hasn't yet been loaded and if parent CultureInfos should be loaded as well for resource inheritance.
  30. /// </summary>
  31. /// <param name="culture"></param>
  32. /// <param name="createIfNotExists"></param>
  33. /// <param name="tryParents"></param>
  34. /// <returns></returns>
  35. public static ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents)
  36. {
  37. return _resourceManagerWrapper.GetResourceSet (culture, createIfNotExists, tryParents)!;
  38. }
  39. /// <summary>
  40. /// Looks up a set of resources for a particular CultureInfo. This is not useful for most users of the ResourceManager
  41. /// - call GetString() or GetObject() instead. The parameters let you control whether the ResourceSet is created if it
  42. /// hasn't yet been loaded and if parent CultureInfos should be loaded as well for resource inheritance. Allows
  43. /// filtering of resources.
  44. /// </summary>
  45. /// <param name="culture"></param>
  46. /// <param name="createIfNotExists"></param>
  47. /// <param name="tryParents"></param>
  48. /// <param name="filter"></param>
  49. /// <returns></returns>
  50. public static ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents, Func<DictionaryEntry, bool>? filter)
  51. {
  52. return _resourceManagerWrapper.GetResourceSet (culture, createIfNotExists, tryParents, filter)!;
  53. }
  54. /// <summary>
  55. /// Looks up a resource value for a particular name. Looks in the specified CultureInfo, and if not found, all parent
  56. /// CultureInfos.
  57. /// </summary>
  58. /// <param name="name"></param>
  59. /// <param name="culture"></param>
  60. /// <returns>Null if the resource was not found in the current culture or the invariant culture.</returns>
  61. public static string GetString (string name, CultureInfo? culture = null!) { return _resourceManagerWrapper.GetString (name, culture); }
  62. }