Skip to content

Commit

Permalink
Use JSON APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed Feb 28, 2023
1 parent ea0bf4d commit ecf7169
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Configuration;
using System.Text.Json;

namespace My.Extensions.Localization.Json.Internal
{
Expand Down Expand Up @@ -175,17 +175,17 @@ IEnumerable<string> GetResourceFiles(string culture)

private static IDictionary<string, string> LoadJsonResources(string filePath)
{
var resources = new Dictionary<string, string>();
if (File.Exists(filePath))
{
var builder = new ConfigurationBuilder()
.AddJsonFile(filePath, optional: true, reloadOnChange: false);
var reader = new StreamReader(filePath);

return new Dictionary<string, string>(builder.Build().AsEnumerable());
}
else
{
return new Dictionary<string, string>();
var document = JsonDocument.Parse(reader.BaseStream);

resources = document.RootElement.EnumerateObject().ToDictionary(e => e.Name, e => e.Value.ToString());
}

return resources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
</ItemGroup>

</Project>

0 comments on commit ecf7169

Please sign in to comment.