Beispiel #1
0
        public IViewComponentResult Invoke()
        {
            //TODO: Better handle culture & uiculture separation!

            var model = new LanguageSwitchViewComponentModel
            {
                CurrentLanguage = new LanguageInfo
                {
                    Name        = CultureInfo.CurrentUICulture.Name,
                    DisplayName = CultureInfo.CurrentUICulture.DisplayName,
                    Icon        = null //TODO!
                }
            };

            foreach (var supportedUiCulture in _options.SupportedUICultures)
            {
                if (model.CurrentLanguage.Name == supportedUiCulture.Name)
                {
                    continue;
                }

                model.OtherLanguages.Add(new LanguageInfo
                {
                    Name        = supportedUiCulture.Name,
                    DisplayName = supportedUiCulture.DisplayName,
                    Icon        = null //TODO!
                });
            }

            return(View("~/Themes/Basic/Components/Toolbar/LanguageSwitch/Default.cshtml", model));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var languages = await _languageProvider.GetLanguagesAsync();

            var currentLanguage = languages.FindByCulture(
                CultureInfo.CurrentCulture.Name,
                CultureInfo.CurrentUICulture.Name
                );

            var model = new LanguageSwitchViewComponentModel
            {
                CurrentLanguage = currentLanguage,
                OtherLanguages  = languages.Where(l => l != currentLanguage).ToList()
            };

            return(View("~/Themes/Basic/Components/Toolbar/LanguageSwitch/Default.cshtml", model));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var languages = await _languageProvider.GetLanguagesAsync();

            var currentLanguage = languages.FindByCulture(
                CultureInfo.CurrentCulture.Name,
                CultureInfo.CurrentUICulture.Name
                );

            if (currentLanguage == null)
            {
                var abpRequestLocalizationOptionsProvider = HttpContext.RequestServices.GetRequiredService <IAbpRequestLocalizationOptionsProvider>();
                var localizationOptions = await abpRequestLocalizationOptionsProvider.GetLocalizationOptionsAsync();

                if (localizationOptions.DefaultRequestCulture != null)
                {
                    currentLanguage = new LanguageInfo(
                        localizationOptions.DefaultRequestCulture.Culture.Name,
                        localizationOptions.DefaultRequestCulture.UICulture.Name,
                        localizationOptions.DefaultRequestCulture.UICulture.DisplayName);
                }
                else
                {
                    currentLanguage = new LanguageInfo(
                        CultureInfo.CurrentCulture.Name,
                        CultureInfo.CurrentUICulture.Name,
                        CultureInfo.CurrentUICulture.DisplayName);
                }
            }

            var model = new LanguageSwitchViewComponentModel
            {
                CurrentLanguage = currentLanguage,
                OtherLanguages  = languages.Where(l => l != currentLanguage).ToList()
            };

            return(View("~/Themes/Basic/Components/Toolbar/LanguageSwitch/Default.cshtml", model));
        }