Skip to content

Commit

Permalink
IStringLocalizer should look for {culture}.json
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed Mar 3, 2020
1 parent 4f13064 commit aee25f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions samples/LocalizationSample/Resources/fr-FR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Hello": "Bonjour"
}
5 changes: 3 additions & 2 deletions samples/LocalizationSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddJsonLocalization(options => options.ResourcesPath = "Resources");
}

public void Configure(IApplicationBuilder app, IHostEnvironment env, IStringLocalizer<Startup> localizer)
public void Configure(IApplicationBuilder app, IHostEnvironment env, IStringLocalizer localizer1, IStringLocalizer<Startup> localizer2)
{
var supportedCultures = new List<CultureInfo>
{
Expand All @@ -40,7 +40,8 @@ public void Configure(IApplicationBuilder app, IHostEnvironment env, IStringLoca

app.Run(async (context) =>
{
await context.Response.WriteAsync($"{localizer["Hello"]}!!");
await context.Response.WriteAsync($"{localizer1["Hello"]}!!");
await context.Response.WriteAsync($"{localizer2["Hello"]}!!");
});
}

Expand Down
10 changes: 4 additions & 6 deletions src/My.Extensions.Localization.Json/JsonStringLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class JsonStringLocalizer : IStringLocalizer
private readonly ILogger _logger;

private string _searchedLocation;

public JsonStringLocalizer(
string resourcesPath,
string resourceName,
Expand Down Expand Up @@ -160,11 +160,9 @@ private void BuildResourcesCache(string culture)
{
_resourcesCache.GetOrAdd(culture, _ =>
{
var resourceFile = $"{culture}.json";
if (_resourceName != null)
{
resourceFile = String.Join(".", _resourceName, resourceFile);
}
var resourceFile = string.IsNullOrEmpty(_resourceName)
? $"{culture}.json"
: $"{_resourceName}.{culture}.json";
_searchedLocation = Path.Combine(_resourcesPath, resourceFile);
IEnumerable<KeyValuePair<string, string>> value = null;
Expand Down

0 comments on commit aee25f5

Please sign in to comment.