Skip to content

Commit 5a95017

Browse files
committed
amend
1 parent a89932c commit 5a95017

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Localization.AspNetCore.EntityFramework/Factories/LocalizerFactory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void ResetCache()
4646
using (var scope = _serviceProvider.GetScopedService(out T context))
4747
{
4848
_cache = context.Set<LocalizationResource>()
49-
.Include(r=>r.Translations)
49+
.Include(r => r.Translations)
5050
.AsNoTracking()
5151
.ToList();
5252
}
@@ -72,19 +72,23 @@ public LocalizedString GetResource(string resourceKey)
7272
throw new ArgumentException(nameof(resourceKey));
7373

7474
var values = _cache
75-
.SelectMany(r=>r.Translations)
75+
.SelectMany(r => r.Translations)
7676
.Where(t => t.Resource.ResourceKey == resourceKey
7777
&& t.Language == CurrentLanguage)
7878
.Select(p => p.Value)
7979
.ToList();
8080

81-
if (_localizerSettings.CreateNewRecordWhenLocalisedStringDoesNotExist && !values.Any())
81+
if (_localizerSettings.CreateNewRecordWhenLocalisedStringDoesNotExist &&
82+
values.Count != SupportedCultures.Count)
83+
{
8284
AddNewResourceKey(resourceKey);
85+
}
8386

8487
var result = values.SingleOrDefault();
8588

8689
if (_localizerSettings.ReturnOnlyKeyIfNotFound && string.IsNullOrWhiteSpace(result))
8790
result = resourceKey;
91+
8892
return new LocalizedString(resourceKey, result!);
8993
}
9094

@@ -135,7 +139,7 @@ private void UpdateCache(string resourceKey)
135139
{
136140
var values = context.Set<LocalizationResource>()
137141
.AsNoTracking()
138-
.Include(r=>r.Translations)
142+
.Include(r => r.Translations)
139143
.Where(r => r.ResourceKey == resourceKey)
140144
.ToList();
141145

0 commit comments

Comments
 (0)