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

Damianedwards/app prefix #176

Merged
merged 1 commit into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class ResourceManagerStringLocalizerFactory : IStringLocalizerFactory
private readonly ConcurrentDictionary<string, ResourceManagerStringLocalizer> _localizerCache =
new ConcurrentDictionary<string, ResourceManagerStringLocalizer>();
private readonly IApplicationEnvironment _applicationEnvironment;

private readonly string _resourcesRelativePath;

/// <summary>
Expand Down Expand Up @@ -69,7 +68,8 @@ public IStringLocalizer Create(Type resourceSource)

var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
? typeInfo.FullName
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath + typeInfo.FullName;
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath
+ TrimPrefix(typeInfo.FullName, _applicationEnvironment.ApplicationName + ".");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some ugly code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree.


return _localizerCache.GetOrAdd(baseName, _ =>
new ResourceManagerStringLocalizer(
Expand All @@ -95,7 +95,7 @@ public IStringLocalizer Create(string baseName, string location)

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(
Expand All @@ -105,5 +105,15 @@ public IStringLocalizer Create(string baseName, string location)
_resourceNamesCache)
);
}

private static string TrimPrefix(string name, string prefix)
{
if (name.StartsWith(prefix, StringComparison.Ordinal))
{
return name.Substring(prefix.Length);
}

return name;
}
}
}