Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Commit e5cb968

Browse files
committed
ResourceManagerStringLocalizerFactory trims app name from resource base name:
- Only applies when LocalizationOptions.ResourcesPath is set - #167
1 parent 2e8ae96 commit e5cb968

File tree

6 files changed

+13
-2
lines changed

6 files changed

+13
-2
lines changed

src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public IStringLocalizer Create(Type resourceSource)
6969

7070
var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
7171
? typeInfo.FullName
72-
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath + typeInfo.FullName;
72+
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath
73+
+ TrimPrefix(typeInfo.FullName, _applicationEnvironment.ApplicationName + ".");
7374

7475
return _localizerCache.GetOrAdd(baseName, _ =>
7576
new ResourceManagerStringLocalizer(
@@ -95,7 +96,7 @@ public IStringLocalizer Create(string baseName, string location)
9596

9697
var rootPath = location ?? _applicationEnvironment.ApplicationName;
9798
var assembly = Assembly.Load(new AssemblyName(rootPath));
98-
baseName = rootPath + "." + _resourcesRelativePath + baseName;
99+
baseName = rootPath + "." + _resourcesRelativePath + TrimPrefix(baseName, rootPath + ".");
99100

100101
return _localizerCache.GetOrAdd(baseName, _ =>
101102
new ResourceManagerStringLocalizer(
@@ -105,5 +106,15 @@ public IStringLocalizer Create(string baseName, string location)
105106
_resourceNamesCache)
106107
);
107108
}
109+
110+
private static string TrimPrefix(string name, string prefix)
111+
{
112+
if (name.StartsWith(prefix, StringComparison.Ordinal))
113+
{
114+
return name.Substring(prefix.Length);
115+
}
116+
117+
return name;
118+
}
108119
}
109120
}

0 commit comments

Comments
 (0)