Пример #1
0
        public IStringLocalizer Create(Type resourceSource)
        {
            var returnOnlyKeyIfNotFound = _options.Value.ReturnOnlyKeyIfNotFound;
            var createNewRecordWhenLocalisedStringDoesNotExist = _options.Value.CreateNewRecordWhenLocalisedStringDoesNotExist;
            SqlStringLocalizer sqlStringLocalizer;

            if (_options.Value.UseOnlyPropertyNames)
            {
                if (_resourceLocalizations.Keys.Contains(Global))
                {
                    return(_resourceLocalizations[Global]);
                }

                sqlStringLocalizer = new SqlStringLocalizer(GetAllResources(Global), Global, returnOnlyKeyIfNotFound, createNewRecordWhenLocalisedStringDoesNotExist);
                return(_resourceLocalizations.GetOrAdd(Global, sqlStringLocalizer));
            }
            else if (_options.Value.UseTypeFullNames)
            {
                if (_resourceLocalizations.Keys.Contains(resourceSource.FullName))
                {
                    return(_resourceLocalizations[resourceSource.FullName]);
                }

                sqlStringLocalizer = new SqlStringLocalizer(GetAllResources(resourceSource.FullName), resourceSource.FullName, returnOnlyKeyIfNotFound, createNewRecordWhenLocalisedStringDoesNotExist);
                return(_resourceLocalizations.GetOrAdd(resourceSource.FullName, sqlStringLocalizer));
            }

            if (_resourceLocalizations.Keys.Contains(resourceSource.Name))
            {
                return(_resourceLocalizations[resourceSource.Name]);
            }

            sqlStringLocalizer = new SqlStringLocalizer(GetAllResources(resourceSource.Name), resourceSource.Name, returnOnlyKeyIfNotFound, createNewRecordWhenLocalisedStringDoesNotExist);
            return(_resourceLocalizations.GetOrAdd(resourceSource.Name, sqlStringLocalizer));
        }
Пример #2
0
        public IStringLocalizer Create(string baseName, string location)
        {
            var returnOnlyKeyIfNotFound = _options.Value.ReturnOnlyKeyIfNotFound;
            var createNewRecordWhenLocalisedStringDoesNotExist = _options.Value.CreateNewRecordWhenLocalisedStringDoesNotExist;

            var resourceKey = baseName + location;

            if (_options.Value.UseOnlyPropertyNames)
            {
                resourceKey = Global;
            }

            if (_resourceLocalizations.Keys.Contains(resourceKey))
            {
                return(_resourceLocalizations[resourceKey]);
            }

            var sqlStringLocalizer = new SqlStringLocalizer(GetAllResources(resourceKey), resourceKey, returnOnlyKeyIfNotFound, createNewRecordWhenLocalisedStringDoesNotExist);

            return(_resourceLocalizations.GetOrAdd(resourceKey, sqlStringLocalizer));
        }