com.vaadin.flow.component.UI.getLocale()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中com.vaadin.flow.component.UI.getLocale()方法的一些代码示例,展示了UI.getLocale()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UI.getLocale()方法的具体详情如下:
包路径:com.vaadin.flow.component.UI
类名称:UI
方法名:getLocale

UI.getLocale介绍

[英]* Gets the locale for this UI.
[中]*获取此UI的区域设置。

代码示例

代码示例来源:origin: com.vaadin/flow-data

private Locale findLocale() {
  Locale locale = null;
  if (UI.getCurrent() != null) {
    locale = UI.getCurrent().getLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  return locale;
}

代码示例来源:origin: com.vaadin/flow-data

/**
 * Finds an appropriate locale to be used in conversion and validation.
 *
 * @return the found locale, not null
 */
protected static Locale findLocale() {
  Locale locale = null;
  if (UI.getCurrent() != null) {
    locale = UI.getCurrent().getLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  return locale;
}

代码示例来源:origin: com.vaadin/flow-server

/**
   * Gets the locale for this component.
   * <p>
   * It returns the {@link UI} locale if it has been set. If there is no
   * {@link UI} locale available then it tries to use the first locale
   * provided by the {@link I18NProvider}. If there is no any provided locale
   * then the default locale is used.
   *
   * @return the component locale
   */
  protected Locale getLocale() {
    UI currentUi = UI.getCurrent();
    Locale locale = currentUi == null ? null : currentUi.getLocale();
    if (locale == null) {
      List<Locale> locales = getI18NProvider().getProvidedLocales();
      if (locales != null && !locales.isEmpty()) {
        locale = locales.get(0);
      } else {
        locale = Locale.getDefault();
      }
    }
    return locale;
  }
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Inform components implementing {@link LocaleChangeObserver} about locale
 * change.
 *
 * @param ui
 *            UI for locale change
 * @param components
 *            components to search
 */
public static void informLocaleChangeObservers(UI ui,
    List<HasElement> components) {
  LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(ui,
      ui.getLocale());
  collectLocaleChangeObservers(components)
      .forEach(observer -> observer.localeChange(localeChangeEvent));
}

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin-flow

@Override
public Optional<Locale> getLocale() {
  // check UI
  final UI currentUi = UI.getCurrent();
  Locale locale = currentUi == null ? null : currentUi.getLocale();
  if (locale == null) {
    // check LocalizationContext
    locale = getLocalizationContext().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale()).orElse(null);
  }
  if (locale == null) {
    // check I18NProvider
    locale = getI18nProvider().map(p -> {
      List<Locale> locales = p.getProvidedLocales();
      if (locales != null && !locales.isEmpty()) {
        return locales.get(0);
      }
      return null;
    }).orElse(null);
  }
  return Optional.ofNullable(locale);
}

代码示例来源:origin: com.vaadin/flow-server

/**
 * Inform components connected to the given ui that implement
 * {@link LocaleChangeObserver} about locale change.
 *
 * @param ui
 *            UI for locale change
 */
public static void informLocaleChangeObservers(UI ui) {
  LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(ui,
      ui.getLocale());
  collectLocaleChangeObservers(ui.getElement())
      .forEach(observer -> observer.localeChange(localeChangeEvent));
}

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin-flow

Locale locale = currentUi == null ? null : currentUi.getLocale();
if (locale == null) {

代码示例来源:origin: com.vaadin/vaadin-date-picker-flow

/**
 * Convenience constructor to create a date picker with a pre-selected date
 * in current UI locale format.
 *
 * @param initialDate
 *            the pre-selected date in the picker
 * @see #setValue(Object)
 */
public DatePicker(LocalDate initialDate) {
  super(initialDate, null, String.class, PARSER, FORMATTER);
  getElement().synchronizeProperty("invalid", "invalid-changed");
  setLocale(UI.getCurrent().getLocale());
}

代码示例来源:origin: com.vaadin/vaadin-time-picker-flow

@Override
protected void onAttach(AttachEvent attachEvent) {
  super.onAttach(attachEvent);
  if (getLocale() == null) {
    setLocale(attachEvent.getUI().getLocale());
  }
  initConnector();
}

代码示例来源:origin: com.vaadin/flow-server

if (ui.isPresent() && component instanceof LocaleChangeObserver) {
  LocaleChangeEvent localeChangeEvent = new LocaleChangeEvent(
      ui.get(), ui.get().getLocale());
  ((LocaleChangeObserver) component).localeChange(localeChangeEvent);

代码示例来源:origin: com.vaadin/flow-server

document.appendChild(doctype);
Element html = document.appendElement("html");
html.attr("lang", context.getUI().getLocale().getLanguage());
Element head = html.appendElement("head");
html.appendElement("body");

代码示例来源:origin: com.vaadin/flow-server

.getSystemMessages(ui.getLocale(), null);

相关文章