private void AddAllTranslations(ILocalizationSource source, IReadOnlyList <LanguageInfo> languages)
 {
     foreach (var language in languages)
     {
         var culture      = new CultureInfo(language.Name);
         var translations = source.GetAllStrings(culture, false);
         AddTranslations(language.Name, translations);
     }
 }
Ejemplo n.º 2
0
        public async Task <PagedResultOutput <LanguageTextListDto> > GetLanguageTexts(GetLanguageTextsInput input)
        {
            if (input.BaseLanguageName.IsNullOrEmpty())
            {
                ApplicationLanguage defaultLanguageOrNullAsync = await this._applicationLanguageManager.GetDefaultLanguageOrNullAsync(this.AbpSession.TenantId);

                ApplicationLanguage applicationLanguage = defaultLanguageOrNullAsync;
                if (applicationLanguage == null)
                {
                    IReadOnlyList <ApplicationLanguage> languagesAsync = await this._applicationLanguageManager.GetLanguagesAsync(this.AbpSession.TenantId);

                    applicationLanguage = languagesAsync.FirstOrDefault <ApplicationLanguage>();
                    if (applicationLanguage == null)
                    {
                        throw new ApplicationException("No language found in the application!");
                    }
                }
                input.BaseLanguageName = applicationLanguage.Name;
            }
            ILocalizationSource source           = this.LocalizationManager.GetSource(input.SourceName);
            CultureInfo         cultureInfo      = CultureInfo.GetCultureInfo(input.BaseLanguageName);
            CultureInfo         cultureInfo1     = CultureInfo.GetCultureInfo(input.TargetLanguageName);
            IQueryable <LanguageTextListDto> key = (
                from localizedString in source.GetAllStrings(true)
                select new LanguageTextListDto()
            {
                Key = localizedString.Name,
                BaseValue = this._applicationLanguageTextManager.GetStringOrNull(this.AbpSession.TenantId, source.Name, cultureInfo, localizedString.Name, true),
                TargetValue = this._applicationLanguageTextManager.GetStringOrNull(this.AbpSession.TenantId, source.Name, cultureInfo1, localizedString.Name, false)
            }).AsQueryable <LanguageTextListDto>();

            if (input.TargetValueFilter == "EMPTY")
            {
                key =
                    from s in key
                    where s.TargetValue.IsNullOrEmpty()
                    select s;
            }
            if (!input.FilterText.IsNullOrEmpty())
            {
                key =
                    from l in key
                    where l.Key != null && l.Key.IndexOf(input.FilterText, StringComparison.CurrentCultureIgnoreCase) >= 0 || l.BaseValue != null && l.BaseValue.IndexOf(input.FilterText, StringComparison.CurrentCultureIgnoreCase) >= 0 || l.TargetValue != null && l.TargetValue.IndexOf(input.FilterText, StringComparison.CurrentCultureIgnoreCase) >= 0
                    select l;
            }
            int num = key.Count <LanguageTextListDto>();

            if (!input.Sorting.IsNullOrEmpty())
            {
                key = key.OrderBy <LanguageTextListDto>(input.Sorting, new object[0]);
            }
            if (input.SkipCount > 0)
            {
                key = key.Skip <LanguageTextListDto>(input.SkipCount);
            }
            if (input.MaxResultCount > 0)
            {
                key = key.Take <LanguageTextListDto>(input.MaxResultCount);
            }
            return(new PagedResultOutput <LanguageTextListDto>(num, key.ToList <LanguageTextListDto>()));
        }