/// <summary> /// Returns a string localizer /// </summary> /// <param name="baseName">Base Name</param> /// <param name="location">Location</param> /// <returns>String Localizer</returns> 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. string resourceBaseName = location + "." + _resourcesRelativePath + LocalizerUtil.TrimPrefix(baseName, location + "."); string 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, _fallbackCulture))); }
/// <summary> /// Returns a string localizer /// </summary> /// <param name="resourceSource">Resource Source</param> /// <returns>String Localizer</returns> public IStringLocalizer Create(Type resourceSource) { if (resourceSource == null) { throw new ArgumentNullException(nameof(resourceSource)); } _logger.LogTrace($"Getting localizer for type {resourceSource}"); TypeInfo typeInfo = resourceSource.GetTypeInfo(); Assembly assembly = typeInfo.Assembly; // Re-root the base name if a resources path is set. string 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, _fallbackCulture))); }