Example #1
0
        [HttpPost] // voor filter form
        public async Task <PagedResultDto <LocalizationDto> > GetAll(LocalizationResultRequestDto input)
        {
            //CheckGetAllPermission();
            var lst = new List <LocalizationDto>();

            foreach (var language in await _languageManager.GetLanguagesAsync(AbpSession.TenantId))
            {
                foreach (var source in _localizationManager.GetAllSources())
                {
                    foreach (var item in source.GetAllStrings(new CultureInfo("en")))
                    {
                        var value = source.GetStringOrNull(item.Name, new CultureInfo(language.Name), false);
                        lst.Add(new LocalizationDto()
                        {
                            Key          = item.Name,
                            Value        = value,
                            Default      = item.Value,
                            LanguageName = language.Name,
                            Source       = source.Name
                        });
                    }
                }
            }
            if (!string.IsNullOrEmpty(input.LanguageSource))
            {
                lst = lst.Where(t => t.Source == input.LanguageSource).ToList();
            }
            if (!string.IsNullOrEmpty(input.LanguageName))
            {
                lst = lst.Where(t => t.LanguageName == input.LanguageName).ToList();
            }
            if (!string.IsNullOrEmpty(input.LanguageKey))
            {
                lst = lst.Where(t => t.Key.ToLower().Contains(input.LanguageKey.ToLower())).ToList();
            }
            if (input.NotTranslatedOnly)
            {
                lst = lst.Where(t => string.IsNullOrEmpty(t.Value)).ToList();
            }
            return(new PagedResultDto <LocalizationDto>()
            {
                Items = lst.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(),
                TotalCount = lst.Count()
            });
        }
Example #2
0
        public override async Task Delete(EntityDto <int> input)
        {
            var language = (await _languageManager.GetLanguagesAsync(AbpSession.TenantId)).FirstOrDefault(l => l.Id == input.Id);

            if (language == null)
            {
                return;
            }
            if (language.Name == "en")
            {
                throw new Abp.UI.UserFriendlyException("Can not delete 'en' language");
            }
            _defaultLanguage = await _languageManager.GetDefaultLanguageOrNullAsync(AbpSession.TenantId);

            if (language.Name == _defaultLanguage.Name)
            {
                throw new Abp.UI.UserFriendlyException("Can not delete default language");
            }
            await _languageManager.RemoveAsync(AbpSession.TenantId, language.Name);
        }