예제 #1
0
        /// <summary>
        /// Add a new resource key
        /// </summary>
        /// <param name="newLocaleResourceKey"></param>
        public LocaleResourceKey Add(LocaleResourceKey newLocaleResourceKey)
        {
            // Trim name to stop any issues
            newLocaleResourceKey.Name = newLocaleResourceKey.Name.Trim();

            // Check to see if a respource key of this name already exists
            var existingResourceKey = _localizationRepository.GetResourceKey(newLocaleResourceKey.Name);

            if (existingResourceKey != null)
            {
                throw new ApplicationException(string.Format("The resource key with name '{0}' already exists.", newLocaleResourceKey.Name));
            }

            newLocaleResourceKey.DateAdded = DateTime.UtcNow;

            // Now add an empty value for each language
            newLocaleResourceKey.LocaleStringResources = new List <LocaleStringResource>();
            foreach (var language in _localizationRepository.GetAll())
            {
                var resourceValue = new LocaleStringResource
                {
                    Language          = language,
                    LocaleResourceKey = newLocaleResourceKey,
                    ResourceValue     = string.Empty
                };

                language.LocaleStringResources.Add(resourceValue);
            }

            //Sanitze
            newLocaleResourceKey = SanitizeLocaleResourceKey(newLocaleResourceKey);

            // Add the key
            return(_localizationRepository.Add(newLocaleResourceKey));
        }
        public List <LocalizationViewModel> GetAll(string columnName, string searchString, Guid countryId)
        {
            List <Localization> entities;

            switch (columnName.ToLower())
            {
            case "localizationkey":
                entities = _repository.GetByLocalizationKey(searchString, countryId);
                break;

            case "localizationvalue":
                entities = _repository.GetByLocalizationValue(searchString, countryId);
                break;

            default:
                entities = _repository.GetAll(countryId);
                break;
            }

            if (entities == null)
            {
                throw new Exception(LOCALIZATION_LOCALIZATIONCLASS_NOT_FOUND);
            }

            return(LocalizationMapper.MapToLocalizationViewModel(entities));
        }
예제 #3
0
 public IEnumerable <LocalizedStringFull> GetAllLocalizedStringsFull()
 {
     return
         (_localizationRepository
          .GetAll()
          .ProjectTo <LocalizedStringFull>()
          .ToList());
 }
        public LocalizedString this[string name]
        {
            get
            {
                var cacheKey =
                    $"{_configuration.GetSection("Cache:Localization:Namespace")?.Value}:" +
                    $"{_culture.Name}:" +
                    $"{name}";

                LocalizedStringBase cachedString =
                    _cache
                    .Get <LocalizedStringBase>(cacheKey);

                if (cachedString != null)
                {
                    return(_mapper.Map <LocalizedStringBase, LocalizedString>(cachedString));
                }

                LocalizedString savedString =
                    _localizationRepository
                    .GetAll()
                    .Where(
                        x =>
                        x.Culture.Equals(_culture.Name) &&
                        x.Key.Equals(name)
                        )
                    .Select(x => new LocalizedString(x.Key, x.Value))
                    .FirstOrDefault();

                if (savedString == null)
                {
                    _logger.LogWarning(
                        $"Cannot find cache key <{cacheKey}> " +
                        $"corresponding to the localization key <{name}> " +
                        $"for culture <{_culture.Name}>." +
                        $"The cache will be populated with a temporary string " +
                        $"till a correct localization is submitted.");
                    savedString = new LocalizedString(name, name, true);
                }
                _cache.Set(cacheKey, _mapper.Map <LocalizedString, LocalizedStringBase>(savedString), "LocalizedString");
                return(savedString);
            }
        }
예제 #5
0
        public void LanguagesInDb()
        {
            var languages = new List <Language> {
                new Language
                {
                    LanguageCulture = "de-AT"
                },
                new Language
                {
                    LanguageCulture = "de-DE"
                }
            };

            _localizationRepositorySub.GetAll().Returns(languages);

            var langsInDb = _localizationService.LanguagesInDb;

            Assert.AreEqual(langsInDb.Count, 2);
        }
예제 #6
0
        public IActionResult List([FromBody] PagingClass paging)
        {
            //var localization = _stringLocalizer.GetAll();

            var angularTable = new DataSourceAngular
            {
                data = (from a in _stringLocalizer.GetAll(paging.pagination, paging.sort, paging.search, paging.search_operator, paging.filter)
                        select new CustomLocalizeModel
                {
                    Resource = a.Key,
                    Arabic = a.LocalizedValue["ar-AE"].ToString(),
                    English = a.LocalizedValue["en-US"].ToString()
                }).ToList(),
                data_count = 0,
                page_count = 1,
            };

            //angularTable.data_count = angularTable.data.Count();
            return(Json(angularTable));
        }
예제 #7
0
        public void Populate()
        {
            var localizedStrings =
                _localizationRepository
                .GetAll()
                .ToList();

            foreach (var localizedString in localizedStrings)
            {
                var cacheKey =
                    $"{_configuration.GetSection("Cache:Localization:Namespace")?.Value}:" +
                    $"{localizedString.Culture}:" +
                    $"{localizedString.Key}";

                _logger.LogInformation($"Cache: populating <{cacheKey}>");

                var localizedStringBase = _mapper.Map <Localization, LocalizedStringBase>(localizedString);
                _cacheService
                .Set(cacheKey, localizedStringBase, "LocalizedString");
            }
        }
예제 #8
0
 public async Task <IEnumerable <LocalizationEntity> > GetAll()
 {
     return(await _localizationRepository.GetAll());
 }