77
88namespace My . Extensions . Localization . Json . Internal ;
99
10+ /// <summary>
11+ /// Provides access to localized string resources loaded from JSON files, supporting culture-specific lookups and
12+ /// optional fallback to parent UI cultures.
13+ /// </summary>
1014public class JsonResourceManager
1115{
1216 private readonly List < JsonFileWatcher > _jsonFileWatchers = [ ] ;
1317 private readonly ConcurrentDictionary < string , ConcurrentDictionary < string , string > > _resourcesCache = new ( ) ;
1418 private readonly ConcurrentDictionary < string , HashSet < string > > _loadedFilesCache = new ( ) ;
1519
20+ /// <summary>
21+ /// Initializes a new instance of the JsonResourceManager class using the specified resource directory and optional
22+ /// resource name.
23+ /// </summary>
24+ /// <param name="resourcesPath">The path to the directory containing the JSON resource files. Cannot be null or empty.</param>
25+ /// <param name="resourceName">The name of the resource to load. If null, the default resource name is used.</param>
1626 public JsonResourceManager ( string resourcesPath , string resourceName = null )
1727 : this ( [ resourcesPath ] , fallBackToParentUICultures : true , resourceName )
1828 {
1929 }
2030
31+ /// <summary>
32+ /// Initializes a new instance of the JsonResourceManager class using the specified resource file paths and
33+ /// configuration options.
34+ /// </summary>
35+ /// <param name="resourcesPaths">An array of file system paths to JSON resource files to be managed. If null, an empty array is used.</param>
36+ /// <param name="fallBackToParentUICultures">Indicates whether resource lookups should fall back to parent UI cultures when a resource is not found for the
37+ /// requested culture.</param>
38+ /// <param name="resourceName">The name of the resource to be managed. If null, the manager will use the default resource name resolution.</param>
2139 public JsonResourceManager ( string [ ] resourcesPaths , bool fallBackToParentUICultures , string resourceName = null )
2240 {
2341 ResourcesPaths = resourcesPaths ?? Array . Empty < string > ( ) ;
@@ -30,15 +48,31 @@ public JsonResourceManager(string[] resourcesPaths, bool fallBackToParentUICultu
3048 }
3149 }
3250
51+ /// <summary>
52+ /// Initializes a new instance of the JsonResourceManager class using the specified resource file paths and an
53+ /// optional resource name.
54+ /// </summary>
55+ /// <param name="resourcesPaths">An array of file system paths to JSON resource files to be managed. Each path should point to a valid resource
56+ /// file. Cannot be null.</param>
57+ /// <param name="resourceName">The name of the resource to be used for lookups. If null, the default resource name will be used.</param>
3358 public JsonResourceManager ( string [ ] resourcesPaths , string resourceName = null )
3459 : this ( resourcesPaths , fallBackToParentUICultures : true , resourceName )
3560 {
3661 }
3762
63+ /// <summary>
64+ /// Gets the name of the resource associated with this instance.
65+ /// </summary>
3866 public string ResourceName { get ; }
3967
68+ /// <summary>
69+ /// Gets the collection of file system paths to resource files associated with the current instance.
70+ /// </summary>
4071 public string [ ] ResourcesPaths { get ; }
4172
73+ /// <summary>
74+ /// Gets the file path to the resources file used by the application.
75+ /// </summary>
4276 public string ResourcesFilePath { get ; private set ; }
4377
4478 /// <summary>
@@ -47,6 +81,15 @@ public JsonResourceManager(string[] resourcesPaths, string resourceName = null)
4781 /// </summary>
4882 public bool FallBackToParentUICultures { get ; }
4983
84+ /// <summary>
85+ /// Retrieves the set of localized resources for the specified culture, optionally including resources from parent
86+ /// cultures.
87+ /// </summary>
88+ /// <param name="culture">The culture for which to retrieve the resource set. This determines which localized resources are returned.</param>
89+ /// <param name="tryParents">If <see langword="true"/>, resources from parent cultures are included in the result; otherwise, only resources
90+ /// for the specified culture are returned.</param>
91+ /// <returns>A <see cref="ConcurrentDictionary{string, string}"/> containing the resources for the specified culture, or <see
92+ /// langword="null"/> if no resources are available for that culture.</returns>
5093 public virtual ConcurrentDictionary < string , string > GetResourceSet ( CultureInfo culture , bool tryParents )
5194 {
5295 TryLoadResourceSet ( culture ) ;
@@ -84,6 +127,11 @@ public virtual ConcurrentDictionary<string, string> GetResourceSet(CultureInfo c
84127 }
85128 }
86129
130+ /// <summary>
131+ /// Retrieves the localized string resource associated with the specified name for the current UI culture.
132+ /// </summary>
133+ /// <param name="name">The name of the resource to retrieve. This value is case-sensitive and must not be null.</param>
134+ /// <returns>The localized string value if found; otherwise, null.</returns>
87135 public virtual string GetString ( string name )
88136 {
89137 var culture = CultureInfo . CurrentUICulture ;
@@ -116,6 +164,13 @@ public virtual string GetString(string name)
116164 return null ;
117165 }
118166
167+ /// <summary>
168+ /// Retrieves the localized string resource associated with the specified name and culture.
169+ /// </summary>
170+ /// <param name="name">The name of the resource to retrieve. This value is case-sensitive and must not be null.</param>
171+ /// <param name="culture">The culture for which the resource should be retrieved. If the resource is not found for this culture and parent
172+ /// culture fallback is enabled, parent cultures will be searched.</param>
173+ /// <returns>The localized string value for the specified resource name and culture, or null if the resource is not found.</returns>
119174 public virtual string GetString ( string name , CultureInfo culture )
120175 {
121176 GetResourceSet ( culture , tryParents : FallBackToParentUICultures ) ;
0 commit comments