Ejemplo n.º 1
0
        public IStringLocalizer Create(string baseName, string location)
        {
            if (baseName == null)
            {
                throw new ArgumentNullException(nameof(baseName));
            }

            _logger.LogVerbose($"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.LogVerbose($"Localizer basename: {resourceBaseName}");

            return(_localizerCache.GetOrAdd(
                       resourceBaseName, new JsonStringLocalizer(resourceBaseName, _applicationEnvironment.ApplicationName, _logger)));
        }
Ejemplo n.º 2
0
        public JsonStringLocalizer(string baseName, string applicationName, ILogger logger)
        {
            this._baseName        = baseName;
            this._applicationName = applicationName;
            this._logger          = logger;

            // Get a list of possible resource file locations.
            _resourceFileLocations = LocalizerUtil.ExpandPaths(baseName, applicationName).ToList();
            foreach (var resFileLocation in _resourceFileLocations)
            {
                logger.LogDebug($"Resource file location base path: {resFileLocation}");
            }
        }
Ejemplo n.º 3
0
        public IStringLocalizer Create(Type resourceSource)
        {
            if (resourceSource == null)
            {
                throw new ArgumentNullException(nameof(resourceSource));
            }

            _logger.LogVerbose($"Getting localizer for type {resourceSource}");

            var typeInfo = resourceSource.GetTypeInfo();
            var assembly = typeInfo.Assembly;

            // Re-root the base name if a resources path is set.
            var resourceBaseName = string.IsNullOrEmpty(_resourcesRelativePath)
                ? typeInfo.FullName
                : _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath +
                                   LocalizerUtil.TrimPrefix(typeInfo.FullName, _applicationEnvironment.ApplicationName + ".");

            _logger.LogVerbose($"Localizer basename: {resourceBaseName}");

            return(_localizerCache.GetOrAdd(
                       resourceBaseName, new JsonStringLocalizer(resourceBaseName, _applicationEnvironment.ApplicationName, _logger)));
        }