private Locale getClientsLocale() { return Page.getCurrent().getWebBrowser().getLocale(); } }
private Locale getClientsLocale() { return Page.getCurrent().getWebBrowser().getLocale(); } }
/** * Sets locale to the browser locale, if available. Browser locale will not be available if the browser is not * active ( this usually only happens in testing or background tasks) * * @param fireListeners * if true, fires change listeners if a change is made * * @return true if the browser was accessible and its locale is supported, false if no suitable locale has been set */ private boolean setLocaleFromBrowser(boolean fireListeners) { WebBrowser webBrowser = browserProvider.get(); if (webBrowser != null) { Locale browserLocale = webBrowser.getLocale(); if (supportedLocales.contains(browserLocale)) { setLocale(browserLocale, fireListeners); return true; } } return false; }
/** * Sets locale to the browser locale, if available. Browser locale will not be available if the browser is not * active ( this usually only happens in testing or background tasks) * * @param fireListeners * if true, fires change listeners if a change is made * * @return true if the browser was accessible and its locale is supported, false if no suitable locale has been set */ private boolean setLocaleFromBrowser(boolean fireListeners) { WebBrowser webBrowser = browserProvider.get(); if (webBrowser != null) { Locale browserLocale = webBrowser.getLocale(); if (supportedLocales.contains(browserLocale)) { setLocale(browserLocale, fireListeners); return true; } } return false; }
public HelpContext getHelpContext(String name) { GuiSpaceService space = spaceList.get(name); if (space == null) return null; HelpContext instance = helpInstanceList.get(name); if (instance == null) { Locale locale = UI.getCurrent().getPage().getWebBrowser().getLocale(); instance = space.createHelpContext(locale); if (instance == null) return null; if (instance instanceof GuiLifecycle) ((GuiLifecycle)instance).doInitialize(); helpInstanceList.put(name, instance); } return instance; }
@Test public void initialise_browser_locale_not_supported_user_not_logged_in() { //given when(browser.getLocale()).thenReturn(Locale.CHINA); when(subject.isAuthenticated()).thenReturn(false); //when currentLocale = createCurrentLocale(); //then assertThat(currentLocale.getLocale()).isEqualTo(defaultLocale); }
@Test public void initialise_user_not_logged_in() { //given when(browser.getLocale()).thenReturn(Locale.GERMANY); when(subject.isAuthenticated()).thenReturn(false); //when currentLocale = createCurrentLocale(); currentLocale.readFromEnvironment(); //then assertThat(currentLocale.getLocale()).isEqualTo(Locale.GERMANY); }
@Test public void initialise_user_option_invalid_browser_invalid() { // given when(browser.getLocale()).thenReturn(Locale.CHINA); when(subject.isAuthenticated()).thenReturn(true); //when currentLocale = createCurrentLocale(); setOption(Locale.CHINA); //then assertThat(currentLocale.getLocale()).isEqualTo(defaultLocale); }
@Test public void initialise_user_already_logged_in() { //given when(browser.getLocale()).thenReturn(Locale.GERMANY); when(subject.isAuthenticated()).thenReturn(true); //when currentLocale = createCurrentLocale(); setOption(Locale.UK); //then assertThat(currentLocale.getLocale()).isEqualTo(Locale.UK); }
@Test public void initialise_browser_locale_not_supported_user_logged_in() { // given when(browser.getLocale()).thenReturn(Locale.CHINA); when(subject.isAuthenticated()).thenReturn(true); //when currentLocale = createCurrentLocale(); setOption(Locale.UK); //then assertThat(currentLocale.getLocale()).isEqualTo(Locale.UK); }
@Test(expected = UnsupportedLocaleException.class) public void set_Locale_not_valid() { //given when(browser.getLocale()).thenReturn(Locale.GERMANY); when(subject.isAuthenticated()).thenReturn(false); currentLocale = createCurrentLocale(); //when currentLocale.setLocale(Locale.CHINA); //then }
@Test public void setLocaleValid() { // given when(browser.getLocale()).thenReturn(Locale.GERMANY); when(subject.isAuthenticated()).thenReturn(false); currentLocale = createCurrentLocale(); currentLocale.readFromEnvironment(); eventBusProvider.get() .subscribe(this); listenerFired = false; // when currentLocale.setLocale(Locale.UK); // then assertThat(listenerFired).isTrue(); }
@Test public void user_logs_out() { //given when(browser.getLocale()).thenReturn(Locale.GERMANY); when(subject.isAuthenticated()).thenReturn(true); //when currentLocale = createCurrentLocale(); setOption(Locale.FRANCE); currentLocale.readFromEnvironment(); //then assertThat(currentLocale.getLocale()).isEqualTo(Locale.FRANCE); //given listenerFired = false; eventBusProvider.get() .subscribe(this); when(subject.isAuthenticated()).thenReturn(false); when(source.identity()).thenReturn("LogoutView"); //when user logs out currentLocale.handleUserHasLoggedIn(new UserHasLoggedIn("id", "david", source)); //then nothing should happen assertThat(currentLocale.getLocale()).isEqualTo(Locale.FRANCE); assertThat(listenerFired).isFalse(); }
.getPage() .getWebBrowser() .getLocale(); } catch (Throwable t) { log.i(t);
contentScreen.setExpandRatio(component, 1f); Locale locale = UI.getCurrent().getPage().getWebBrowser().getLocale();
di.setLocale(webBrowser.getLocale());