Skip to content

Commit aee25f5

Browse files
committed
IStringLocalizer should look for {culture}.json
1 parent 4f13064 commit aee25f5

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Hello": "Bonjour"
3+
}

samples/LocalizationSample/Startup.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void ConfigureServices(IServiceCollection services)
1717
services.AddJsonLocalization(options => options.ResourcesPath = "Resources");
1818
}
1919

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

4141
app.Run(async (context) =>
4242
{
43-
await context.Response.WriteAsync($"{localizer["Hello"]}!!");
43+
await context.Response.WriteAsync($"{localizer1["Hello"]}!!");
44+
await context.Response.WriteAsync($"{localizer2["Hello"]}!!");
4445
});
4546
}
4647

src/My.Extensions.Localization.Json/JsonStringLocalizer.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class JsonStringLocalizer : IStringLocalizer
2020
private readonly ILogger _logger;
2121

2222
private string _searchedLocation;
23-
23+
2424
public JsonStringLocalizer(
2525
string resourcesPath,
2626
string resourceName,
@@ -160,11 +160,9 @@ private void BuildResourcesCache(string culture)
160160
{
161161
_resourcesCache.GetOrAdd(culture, _ =>
162162
{
163-
var resourceFile = $"{culture}.json";
164-
if (_resourceName != null)
165-
{
166-
resourceFile = String.Join(".", _resourceName, resourceFile);
167-
}
163+
var resourceFile = string.IsNullOrEmpty(_resourceName)
164+
? $"{culture}.json"
165+
: $"{_resourceName}.{culture}.json";
168166

169167
_searchedLocation = Path.Combine(_resourcesPath, resourceFile);
170168
IEnumerable<KeyValuePair<string, string>> value = null;

0 commit comments

Comments
 (0)