ResourceManagerStringLocalizerFactory trims app name from resource base name:
- Only applies when LocalizationOptions.ResourcesPath is set - #167
This commit is contained in:
parent
2e8ae969b7
commit
e72d3cb249
|
|
@ -20,7 +20,6 @@ namespace Microsoft.Extensions.Localization
|
|||
private readonly ConcurrentDictionary<string, ResourceManagerStringLocalizer> _localizerCache =
|
||||
new ConcurrentDictionary<string, ResourceManagerStringLocalizer>();
|
||||
private readonly IApplicationEnvironment _applicationEnvironment;
|
||||
|
||||
private readonly string _resourcesRelativePath;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -69,7 +68,8 @@ namespace Microsoft.Extensions.Localization
|
|||
|
||||
var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
|
||||
? typeInfo.FullName
|
||||
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath + typeInfo.FullName;
|
||||
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath
|
||||
+ TrimPrefix(typeInfo.FullName, _applicationEnvironment.ApplicationName + ".");
|
||||
|
||||
return _localizerCache.GetOrAdd(baseName, _ =>
|
||||
new ResourceManagerStringLocalizer(
|
||||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.Extensions.Localization
|
|||
|
||||
var rootPath = location ?? _applicationEnvironment.ApplicationName;
|
||||
var assembly = Assembly.Load(new AssemblyName(rootPath));
|
||||
baseName = rootPath + "." + _resourcesRelativePath + baseName;
|
||||
baseName = rootPath + "." + _resourcesRelativePath + TrimPrefix(baseName, rootPath + ".");
|
||||
|
||||
return _localizerCache.GetOrAdd(baseName, _ =>
|
||||
new ResourceManagerStringLocalizer(
|
||||
|
|
@ -105,5 +105,15 @@ namespace Microsoft.Extensions.Localization
|
|||
_resourceNamesCache)
|
||||
);
|
||||
}
|
||||
|
||||
private static string TrimPrefix(string name, string prefix)
|
||||
{
|
||||
if (name.StartsWith(prefix, StringComparison.Ordinal))
|
||||
{
|
||||
return name.Substring(prefix.Length);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue