Пример #1
0
        public PartialViewResult EditTextModal(
            string sourceName,
            string baseLanguageName,
            string languageName,
            string key, bool isEdit = true)
        {
            var languages = _languageManager.GetLanguages();

            var baselanguage = languages.FirstOrDefault(l => l.Name == baseLanguageName);

            if (baselanguage == null)
            {
                throw new Exception("Could not find language: " + baseLanguageName);
            }

            var targetLanguage = languages.FirstOrDefault(l => l.Name == languageName);

            if (targetLanguage == null)
            {
                throw new Exception("Could not find language: " + languageName);
            }

            string baseText   = string.Empty;
            string targetText = string.Empty;

            if (!string.IsNullOrEmpty(key))
            {
                baseText = _applicationLanguageTextManager.GetStringOrNull(
                    AbpSession.TenantId,
                    sourceName,
                    CultureInfo.GetCultureInfo(baseLanguageName),
                    key
                    );

                targetText = _applicationLanguageTextManager.GetStringOrNull(
                    AbpSession.TenantId,
                    sourceName,
                    CultureInfo.GetCultureInfo(languageName),
                    key,
                    false
                    );
            }
            var viewModel = new EditTextModalViewModel
            {
                SourceName     = sourceName,
                BaseLanguage   = baselanguage,
                TargetLanguage = targetLanguage,
                BaseText       = baseText,
                TargetText     = targetText,
                Key            = key,
                IsEdit         = isEdit
            };

            return(PartialView("_EditTextModal", viewModel));
        }
Пример #2
0
        public async Task <List <AppLanguageTextListDto> > GetAllLanguageTexts(GetAllLanguageTextsInput input)
        {
            if (input.LanguageName.IsNullOrEmpty())
            {
                var defaultLanguage =
                    await _applicationLanguageManager.GetDefaultLanguageOrNullAsync(AbpSession.TenantId);

                if (defaultLanguage == null)
                {
                    defaultLanguage = (await _applicationLanguageManager.GetLanguagesAsync(AbpSession.TenantId))
                                      .FirstOrDefault();
                    if (defaultLanguage == null)
                    {
                        throw new Exception("No language found in the application!");
                    }
                }

                input.LanguageName = defaultLanguage.Name;
            }

            var source        = LocalizationManager.GetSource(AdminConsts.AppLocalizationSourceName);
            var targetCulture = CultureInfo.GetCultureInfo(input.LanguageName);

            var languageTexts = source
                                .GetAllStrings()
                                .Select(localizedString => new AppLanguageTextListDto
            {
                Key   = localizedString.Name,
                Value = _applicationLanguageTextManager.GetStringOrNull(AbpSession.TenantId, source.Name,
                                                                        targetCulture, localizedString.Name, false)
            })
                                .AsQueryable();

            return(languageTexts.ToList());
        }
        public string GetStringOrNull(GetStringOrNullInput input)
        {
            var text = _applicationLanguageTextManager.GetStringOrNull(input.TenantId, input.SourceName,
                                                                       new CultureInfo(input.CultureName), input.Key, input.TryDefaults);

            return(text);
        }
        public async Task <PagedResultDto <LanguageTextListDto> > GetLanguageTexts(GetLanguageTextsInput input)
        {
            /* Note: This method is used by SPA without paging, MPA with paging.
             * So, it can both usable with paging or not */

            //Normalize base language name
            if (input.BaseLanguageName.IsNullOrEmpty())
            {
                var defaultLanguage = await _applicationLanguageManager.GetDefaultLanguageOrNullAsync(AbpSession.TenantId);

                if (defaultLanguage == null)
                {
                    defaultLanguage = (await _applicationLanguageManager.GetLanguagesAsync(AbpSession.TenantId)).FirstOrDefault();
                    if (defaultLanguage == null)
                    {
                        throw new ApplicationException("No language found in the application!");
                    }
                }

                input.BaseLanguageName = defaultLanguage.Name;
            }

            var source        = LocalizationManager.GetSource(input.SourceName);
            var baseCulture   = CultureInfo.GetCultureInfo(input.BaseLanguageName);
            var targetCulture = CultureInfo.GetCultureInfo(input.TargetLanguageName);

            var languageTexts = source
                                .GetAllStrings()
                                .Select(localizedString => new LanguageTextListDto
            {
                Key         = localizedString.Name,
                BaseValue   = _applicationLanguageTextManager.GetStringOrNull(AbpSession.TenantId, source.Name, baseCulture, localizedString.Name),
                TargetValue = _applicationLanguageTextManager.GetStringOrNull(AbpSession.TenantId, source.Name, targetCulture, localizedString.Name, false)
            })
                                .AsQueryable();

            //Filters
            if (input.TargetValueFilter == "EMPTY")
            {
                languageTexts = languageTexts.Where(s => s.TargetValue.IsNullOrEmpty());
            }

            if (!input.FilterText.IsNullOrEmpty())
            {
                languageTexts = languageTexts.Where(
                    l => (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)
                    );
            }

            var totalCount = languageTexts.Count();

            //Ordering
            if (!input.Sorting.IsNullOrEmpty())
            {
                languageTexts = languageTexts.OrderBy(input.Sorting);
            }

            //Paging
            if (input.SkipCount > 0)
            {
                languageTexts = languageTexts.Skip(input.SkipCount);
            }

            if (input.MaxResultCount > 0)
            {
                languageTexts = languageTexts.Take(input.MaxResultCount);
            }

            return(new PagedResultDto <LanguageTextListDto>(
                       totalCount,
                       languageTexts.ToList()
                       ));
        }
Пример #5
0
 public string GetStringOrNull(int?tenantId, string sourceName, CultureInfo culture, string key)
 {
     return(_languagetextManager.GetStringOrNull(tenantId, sourceName, culture, key));
 }