Пример #1
0
        public PartialViewResult LanguageSelector()
        {
            var cache = cacheService.Get("LanguageSelector",
                () =>
                {
                    var langCodes = (from t in db.Translations
                                     where t.Area == TranslationArea.Backend
                                     select t.LanguageCode).Distinct().ToList();

                    var model = new LanguageSelectorViewModel();

                    if (!langCodes.Contains("en"))
                    {
                        model.Languages.Add(new LanguageViewModel { Code = "en", DisplayName = "English" });
                    }
                    foreach (var code in langCodes)
                    {
                        var culture = CultureInfo.GetCultureInfo(code);
                        model.Languages.Add(new LanguageViewModel
                        {
                            Code = code,
                            DisplayName = culture.NativeName
                        });
                    }
                    return model;
                });

            return PartialView(cache);
        }
Пример #2
0
        public LanguageSelector()
        {
            InitializeComponent();
            var languageSelectorViewModel = new LanguageSelectorViewModel();

            DataContext = languageSelectorViewModel;
        }
Пример #3
0
        public PartialViewResult LanguageSelector()
        {
            var cache = cacheService.Get("LanguageSelector",
                                         () =>
            {
                var langCodes = (from t in db.Translations
                                 where t.Area == TranslationArea.Backend
                                 select t.LanguageCode).Distinct().ToList();

                var model = new LanguageSelectorViewModel();

                if (!langCodes.Contains("en"))
                {
                    model.Languages.Add(new LanguageViewModel {
                        Code = "en", DisplayName = "English"
                    });
                }
                foreach (var code in langCodes)
                {
                    var culture = CultureInfo.GetCultureInfo(code);
                    model.Languages.Add(new LanguageViewModel
                    {
                        Code        = code,
                        DisplayName = culture.NativeName
                    });
                }
                return(model);
            });

            return(PartialView(cache));
        }
        public void GetViewModel_ShouldReturnProperResult(
            Language language,
            Item item,
            Database database,
            LanguageCollection languages,
            ILanguageSelectorSettings dataSource,
            LanguageSelectorViewModel expectedResult)
        {
            _mvcContext
            .Setup(x => x.GetDataSourceItem <ILanguageSelectorSettings>())
            .Returns(dataSource);
            _languageManager
            .Setup(x => x.GetLanguages(database))
            .Returns(languages);
            _linkManager
            .Setup(x => x.GetItemUrl(It.IsAny <Item>(), It.IsAny <ItemUrlBuilderOptions>()))
            .Returns(expectedResult.Languages.First().Link);

            var result = _multiLanguageService.GetViewModel(language, item, database);

            Assert.Equal(expectedResult.CurrentLanguageName, result.CurrentLanguageName);
            Assert.Equal(expectedResult.Languages.First().DisplayName, result.Languages.First().DisplayName);
            Assert.Equal(expectedResult.Languages.First().Link, result.Languages.First().Link);
            Assert.Equal(expectedResult.LanguageSelectorSettings, dataSource);
        }
Пример #5
0
        public ActionResult LanguageSelector()
        {
            var countryPage = CurrentPage.AncestorOrSelf <CountryPage>();

            var model = new LanguageSelectorViewModel
            {
                Languages = countryPage
                            .Children <LanguagePage>()
                            .OrderBy(l => l.LanguageName),

                Current = CurrentPage.AncestorOrSelf <LanguagePage>()
            };

            if (model.Languages.Count() < 2)
            {
                return(Content(string.Empty));
            }

            // Here we are using the home page url,
            // not the language page url

            foreach (var language in model.Languages)
            {
                language.HomePageUrl = language.FirstChild <HomePage>().Url;
            }

            return(PartialView("LanguageSelector", model));
        }
Пример #6
0
        public ActionResult LanguageSelector()
        {
            var currentCulture = CultureHelper.GetCurrentCulture();
            IEnumerable <string> userCultures = CultureHelper.GetSupportedCultures();

            var model = LanguageSelectorViewModel.Create(currentCulture, userCultures);

            return(PartialView(model));
        }
Пример #7
0
 public SettingsViewModel()
 {
     LoggingSettings             = new LoggingSettingsViewModel();
     SafeVariableSettings        = new SafeVariableViewModel();
     ConsoleAppearanceSettings   = new ConsoleAppearanceViewModel();
     WatchedApplicationSettings  = new WatchedApplicationControlViewModel();
     LanguageSettings            = new LanguageSelectorViewModel();
     MainWindowBehaviourSettings = new MainWindowSavedBehaviourViewModel();
     MinimizationBehaviour       = new MinimizationBehaviourViewModel();
 }
        public static IEnumerable <object[]> CorrectData()
        {
            var language   = new Mock <Language>();
            var database   = new Mock <Database>();
            var item       = CreateItem();
            var dataSource = new Mock <ILanguageSelectorSettings>();

            var cultureInfo = new CultureInfo("en");

            language.Setup(x => x.CultureInfo).Returns(cultureInfo);

            var cultureInfoToList = new CultureInfo("ru-RU");
            var languageToList    = new Mock <Language>();

            languageToList.Setup(x => x.CultureInfo).Returns(cultureInfoToList);

            var expectedResult = new LanguageSelectorViewModel
            {
                CurrentLanguageName      = "English",
                LanguageSelectorSettings = dataSource.Object,
                Languages = new List <LanguageViewModel>
                {
                    new LanguageViewModel
                    {
                        Link        = "/" + cultureInfoToList.Name + "/",
                        DisplayName = "Русский"
                    }
                }
            };

            return(new List <object[]>
            {
                new object[]
                {
                    language.Object, item, database.Object,
                    new LanguageCollection {
                        languageToList.Object
                    },
                    dataSource.Object, expectedResult
                }
            });
        }
        /// <inheritdoc />
        public LanguageSelectorViewModel CreateViewModel()
        {
            var viewModel = new LanguageSelectorViewModel();
            viewModel.IncludeCurrentLanguage = this.IncludeCurrentLanguage;
            viewModel.CurrentLanguage = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
            viewModel.CssClass = this.CssClass;

            IEnumerable<CultureInfo> shownLanguages = this.GetLanguagesToDisplay();

            foreach (var lang in shownLanguages)
            {
                var langName = this.GetDisplayedLanguageName(lang);
                var url = this.GetUrlForLanguage(lang);
                url = RouteHelper.ResolveUrl(url, UrlResolveOptions.Absolute);

                viewModel.Languages.Add(new LanguageSelectorItem(langName, url, lang.Name));
            }

            return viewModel;
        }
        /// <summary>
        /// Renders appropriate view depending on the <see cref="TemplateName"/>
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Index()
        {
            var context = this.CurrentHttpContext;

            if (context.Items.Contains("IsTemplate") && (bool)context.Items["IsTemplate"])
            {
                return this.Content(this.LanguageSelectorOnTemplateMessage);
            }

            this.viewModel = this.Model.CreateViewModel();

            var page = context.CurrentHandler.GetPageHandler();

            if (page != null && !this.IsEdit)
            {
                page.PreRenderComplete += this.PagePreRenderCompleteHandler;
            }

            var fullTemplateName = this.templateNamePrefix + this.TemplateName;

            return this.View(fullTemplateName, this.viewModel);
        }
 public LanguageSelectorView()
 {
     DataContext = new LanguageSelectorViewModel();
     InitializeComponent();
 }
Пример #12
0
 public LanguageSelectorControl()
 {
     _viewModel  = new LanguageSelectorViewModel();
     DataContext = _viewModel;
     InitializeComponent();
 }