public IStringLocalizer Create(string baseName, string location) { if (baseName == null) { throw new ArgumentNullException(nameof(baseName)); } _logger.LogTrace($"Getting localizer for baseName {baseName} and location {location}"); location = location ?? _applicationEnvironment.ApplicationName; // Re-root base name if a resources path is set and strip the cshtml part. var resourceBaseName = location + "." + _resourcesRelativePath + LocalizerUtil.TrimPrefix(baseName, location + "."); var viewExtension = KnownViewExtensions.FirstOrDefault(extension => resourceBaseName.EndsWith(extension)); if (viewExtension != null) { resourceBaseName = resourceBaseName.Substring(0, resourceBaseName.Length - viewExtension.Length); } _logger.LogTrace($"Localizer basename: {resourceBaseName}"); return(_localizerCache.GetOrAdd( resourceBaseName, new JsonStringLocalizer(resourceBaseName, _applicationEnvironment.ApplicationName, _logger, _options))); }
public IStringLocalizer Create(Type resourceSource) { if (resourceSource == null) { throw new ArgumentNullException(nameof(resourceSource)); } _logger.LogTrace($"Getting localizer for type {resourceSource}"); var typeInfo = resourceSource.GetTypeInfo(); var assemblyName = typeInfo.Assembly.GetName(); var resourceBaseName = string.Empty; if (Assembly.GetEntryAssembly().FullName != typeInfo.Assembly.FullName) { // Different logic if coming from another assembly resourceBaseName = string.IsNullOrEmpty(_resourcesRelativePath) ? typeInfo.FullName : assemblyName.Name + "." + _resourcesRelativePath + "." + typeInfo.Name; } else { // Re-root the base name if a resources path is set. resourceBaseName = string.IsNullOrEmpty(_resourcesRelativePath) ? typeInfo.FullName : _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath + LocalizerUtil.TrimPrefix(typeInfo.FullName, _applicationEnvironment.ApplicationName + "."); } _logger.LogTrace($"Localizer basename: {resourceBaseName}"); return(_localizerCache.GetOrAdd( resourceBaseName, new JsonStringLocalizer(resourceBaseName, _applicationEnvironment.ApplicationName, _logger, _options))); }