!1622 fix(#I41ZUB): resolve localization in WTM not retrieve right resource from resx file

* fix: 修复本地化上一个工厂未找到资源逻辑判断
* refactor: 优化 Factory 类增加修饰符
This commit is contained in:
Argo 2021-07-22 09:37:37 +00:00
parent 139b9e0327
commit 8f670a6281
2 changed files with 7 additions and 5 deletions

View File

@ -81,7 +81,8 @@ namespace BootstrapBlazor.Localization.Json
if (type != null) if (type != null)
{ {
var localizer = factory.Create(type); var localizer = factory.Create(type);
ret = localizer[name]; var l = localizer[name];
ret = l.ResourceNotFound ? null : l.Value;
} }
} }
} }
@ -98,9 +99,10 @@ namespace BootstrapBlazor.Localization.Json
{ {
get get
{ {
var format = base.GetStringSafely(name, CultureInfo.CurrentUICulture) ?? GetJsonStringSafely(name); var format = base.GetStringSafely(name, CultureInfo.CurrentUICulture)
?? GetStringFromInject(name)
?? GetJsonStringSafely(name);
var value = !string.IsNullOrEmpty(format) ? string.Format(format, arguments) : name; var value = !string.IsNullOrEmpty(format) ? string.Format(format, arguments) : name;
return new LocalizedString(name, value, resourceNotFound: format == null, searchedLocation: _searchedLocation); return new LocalizedString(name, value, resourceNotFound: format == null, searchedLocation: _searchedLocation);
} }
} }

View File

@ -21,7 +21,7 @@ namespace BootstrapBlazor.Localization.Json
private readonly JsonLocalizationOptions _jsonOptions; private readonly JsonLocalizationOptions _jsonOptions;
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
private string? _typeName; private string? _typeName;
private IServiceProvider _provider; private readonly IServiceProvider _provider;
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
@ -87,7 +87,7 @@ namespace BootstrapBlazor.Localization.Json
/// 获得 IResourceNamesCache 实例 /// 获得 IResourceNamesCache 实例
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IResourceNamesCache GetCache() internal IResourceNamesCache GetCache()
{ {
var field = this.GetType().BaseType?.GetField("_resourceNamesCache", BindingFlags.NonPublic | BindingFlags.Instance); var field = this.GetType().BaseType?.GetField("_resourceNamesCache", BindingFlags.NonPublic | BindingFlags.Instance);
var ret = field?.GetValue(this) as IResourceNamesCache; var ret = field?.GetValue(this) as IResourceNamesCache;