You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using ASP.NET Core 2 together with this adaptation of AspNetCoreLocalization. I'm however a bit 'stuck' on resetting the cache for my data annotation translations.
When I reset the cache, everything is updated (global translations (custom) and my resource translations) however, my data annotations refuse to be 'updated', even though they should be used as resource translations (stock behaviour).
I had same problem... seems to be a problem with DataAnnotation resource that in some way continue to reference the first ISqlLocalizer object created, also after cleaning the internal cache dictionary.
I solved in this way:
SqlStringLocalizerFactory.cs :
public void ResetCache()
{
lock (_context)
{
_context.DetachAllEntities();
}
foreach (String localizerKey in _resourceLocalizations.Keys)
{
SqlStringLocalizer localizer = _resourceLocalizations[localizerKey] as SqlStringLocalizer;
localizer.ReloadLocalizations(GetAllFromDatabaseForResource(localizerKey));
}
}
public void ResetCache(Type resourceSource)
{
lock (_context)
{
_context.DetachAllEntities();
}
IStringLocalizer returnValue;
if (_resourceLocalizations.TryGetValue(resourceSource.FullName, out returnValue))
{
SqlStringLocalizer localizer = _resourceLocalizations[resourceSource.FullName] as SqlStringLocalizer;
localizer.ReloadLocalizations(GetAllFromDatabaseForResource(resourceSource.FullName));
}
}
Activity
velorium-star commentedon Jan 23, 2019
+1 Exactly this happens to me also.
sihon82 commentedon Jan 30, 2020
I had same problem... seems to be a problem with DataAnnotation resource that in some way continue to reference the first ISqlLocalizer object created, also after cleaning the internal cache dictionary.
I solved in this way:
SqlStringLocalizerFactory.cs :
SqlStringLocalizer.cs:
JoeGoodwin commentedon May 21, 2021
Could this bug fix be implemented please?