This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Manually switching locale
Skip to end of metadata
Go to start of metadata

To manually switch the locale:

public final class MyPage extends WebPage {

	...

	add(new Link("languageSwitch") {

		@Override
		public final void onClick() {
			Locale locale = new Locale(MyPage.this.getString("header.versionLanguage"));
			this.getSession().setLocale(locale);
		}

	});

	...

}
  • No labels

1 Comment

  1. I've created a LocaleLink which you can add to your page. It will not show if it is the current Locale

    import java.util.Locale;
    
    import org.apache.wicket.markup.html.link.Link;
    
    /**
     * @author Herman Suijs
     */
    public final class LocaleLink extends Link
    {
        /**
         * Dummy serial version uid.
         */
        private static final long serialVersionUID = 1L;
    
        /**
         * Locale for this link.
         */
        private final Locale      locale;
    
        /**
         * Constructor for a new LocaleLink.
         * 
         * @param wicketId Id of wicket component
         * @param localeString Locale to switch to
         */
        public LocaleLink(final String wicketId, final String localeString)
        {
            super(wicketId);
            this.locale = new Locale(localeString);
        }
    
        /**
         * Constructor with locale.
         * 
         * @param wicketId Id of wicket component
         * @param locale Locale to switch to
         */
        public LocaleLink(final String wicketId, final Locale locale)
        {
            super(wicketId);
            this.locale = locale;
        }
    
        /**
         * On click of a user.
         */
        @Override
        public void onClick()
        {
            this.getSession().setLocale(this.locale);
        }
    
        /**
         * Determine if visible.
         * 
         * @return True if locale for component is different from locale in session.
         */
        @Override
        public boolean isVisible()
        {
            return !this.getSession().getLocale().equals(this.locale);
        }
    }