Esempio n. 1
0
 public void checkR() {
   if (English.isChecked()) {
     lenguaje = "en";
     Locale preferredLocale = org.zkoss.util.Locales.getLocale(lenguaje);
     session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
   } else if (Spanish.isChecked()) {
     lenguaje = "es";
     Locale preferredLocale = org.zkoss.util.Locales.getLocale(lenguaje);
     session.setAttribute(org.zkoss.web.Attributes.PREFERRED_LOCALE, preferredLocale);
   }
 }
Esempio n. 2
0
  /**
   * Returns the preferred locale of the specified request. You rarely need to invoke this method
   * directly, because it is done automatically by {@link #setup}.
   *
   * <ol>
   *   <li>It checks whether any attribute stored in HttpSession called {@link
   *       Attributes#PREFERRED_LOCALE}. If so, return it.
   *   <li>If not found, it checks if the servlet context has the attribute called {@link
   *       Attributes#PREFERRED_LOCALE}. If so, return it.
   *   <li>If not found, it checks if the library property called {@link
   *       Attributes#PREFERRED_LOCALE} is defined. If so, return it.
   *   <li>Otherwise, use ServletRequest.getLocale().
   * </ol>
   *
   * @param sess the session to look for the preferred locale. Ignored if null.
   */
  public static final Locale getPreferredLocale(HttpSession sess, ServletRequest request) {
    if (sess != null) {
      Object v = sess.getAttribute(Attributes.PREFERRED_LOCALE);
      if (v == null)
        v = sess.getAttribute(PX_PREFERRED_LOCALE); // backward compatible (prior to 5.0.3)
      if (v != null) {
        if (v instanceof Locale) return (Locale) v;
        logLocaleError(v);
      }

      v = sess.getServletContext().getAttribute(Attributes.PREFERRED_LOCALE);
      if (v == null)
        v =
            sess.getServletContext()
                .getAttribute(PX_PREFERRED_LOCALE); // backward compatible (prior to 5.0.3)
      if (v != null) {
        if (v instanceof Locale) return (Locale) v;
        logLocaleError(v);
      }

      final String s = Library.getProperty(Attributes.PREFERRED_LOCALE);
      if (s != null) return Locales.getLocale(s);
    }

    Locale l = request.getLocale();
    // B65-ZK-1916: convert zh_HANS-XX and zh_HANT-XX to zh_XX
    return l != null ? fixZhLocale(l) : Locale.getDefault();
  }
Esempio n. 3
0
 /**
  * Sets the locale used to identify the format of this datebox.
  *
  * <p>Default: null (i.e., {@link Locales#getCurrent}, the current locale is assumed)
  *
  * @since 5.0.7
  */
 public void setLocale(String locale) {
   setLocale(locale != null && locale.length() > 0 ? Locales.getLocale(locale) : null);
 }