congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
GlobalConfig.getAvailableLocales
Code IndexAdd Tabnine to your IDE (free)

How to use
getAvailableLocales
method
in
com.haulmont.cuba.core.global.GlobalConfig

Best Java code snippets using com.haulmont.cuba.core.global.GlobalConfig.getAvailableLocales (Showing top 20 results out of 315)

origin: com.haulmont.cuba/cuba-global

/**
 * @return first locale from the list defined in {@code cuba.availableLocales} app property, taking into
 * account {@link #useLocaleLanguageOnly()} return value.
 */
public Locale getDefaultLocale() {
  if (globalConfig.getAvailableLocales().isEmpty())
    throw new DevelopmentException("Invalid cuba.availableLocales application property");
  return globalConfig.getAvailableLocales().entrySet().iterator().next().getValue();
}
origin: com.haulmont.cuba/cuba-rest-api

protected Locale localeFromString(String localeStr) {
  return StringUtils.isBlank(localeStr) ?
      globalConfig.getAvailableLocales().values().iterator().next()
      : LocaleUtils.toLocale(localeStr);
}
origin: com.haulmont.cuba/cuba-global

/**
 * @return whether to use a full locale representation, or language only. Returns true if all locales listed
 * in {@code cuba.availableLocales} app property are language only.
 */
public boolean useLocaleLanguageOnly() {
  if (useLocaleLanguageOnly == null) {
    boolean found = false;
    for (Locale locale : globalConfig.getAvailableLocales().values()) {
      if (!StringUtils.isEmpty(locale.getCountry()) || !StringUtils.isEmpty(locale.getVariant())) {
        useLocaleLanguageOnly = false;
        found = true;
        break;
      }
    }
    if (!found)
      useLocaleLanguageOnly = true;
  }
  return useLocaleLanguageOnly;
}
origin: com.haulmont.cuba/cuba-gui

@Override
public void init(Map<String, Object> params) {
  Map<String, Locale> map = globalConfig.getAvailableLocales();
  for (Map.Entry<String, Locale> entry : map.entrySet()) {
    localesScrollBox.add(createLocaleListComponent(entry.getValue(), entry.getKey()));
  }
}
origin: com.haulmont.cuba/cuba-rest-api

  /**
   * Method extracts locale information from the Accept-Language header. If no such header is specified or the
   * passed locale is not among application available locales, then null is returned
   */
  @Nullable
  public Locale extractLocaleFromRequestHeader(HttpServletRequest request) {
    Locale locale = null;
    if (!Strings.isNullOrEmpty(request.getHeader(HttpHeaders.ACCEPT_LANGUAGE))) {
      Locale requestLocale = request.getLocale();

      GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
      Map<String, Locale> availableLocales = globalConfig.getAvailableLocales();
      if (availableLocales.values().contains(requestLocale)) {
        locale = requestLocale;
      } else {
        log.warn("Locale {} passed in the Accept-Language header is not supported by the application. It was ignored.");
      }
    }
    return locale;
  }
}
origin: com.haulmont.cuba/cuba-idp

@GetMapping(value = "/locales", produces = "application/json; charset=UTF-8")
@ResponseBody
public LocalesInfo getLocales() {
  LocalesInfo localesInfo = new LocalesInfo();
  localesInfo.setLocaleSelectVisible(globalConfig.getLocaleSelectVisible());
  Map<String, String> locales = new LinkedHashMap<>();
  for (Map.Entry<String, Locale> entry : globalConfig.getAvailableLocales().entrySet()) {
    locales.put(entry.getValue().toLanguageTag(), entry.getKey());
  }
  localesInfo.setLocales(locales);
  return localesInfo;
}
origin: com.haulmont.cuba/cuba-portal

  public Properties getFreeMarkerSettings() {
    GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class);
    Map<String, Locale> availableLocales = globalConfig.getAvailableLocales();
    if (availableLocales.isEmpty()) {
      throw new IllegalStateException("Property cuba.availableLocales is not configured");
    }

    Locale locale = availableLocales.values().iterator().next();
    FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(locale);

    final Properties freemarkerSettings = new Properties();
    freemarkerSettings.setProperty("number_format", "#");
    freemarkerSettings.setProperty("datetime_format", formatStrings.getDateTimeFormat());
    freemarkerSettings.setProperty("date_format", formatStrings.getDateFormat());
    freemarkerSettings.setProperty("template_exception_handler", "rethrow");
    return freemarkerSettings;
  }
}
origin: com.haulmont.fts/fts-global

private String formatEnum(Enum enumValue) {
  Messages messages = AppBeans.get(Messages.class);
  GlobalConfig globalConfig = AppBeans.get(Configuration.class).getConfig(GlobalConfig.class);
  Set<String> localizedValues = new HashSet<>();
  for (Locale locale : globalConfig.getAvailableLocales().values()) {
    localizedValues.add(messages.getMessage(enumValue, locale));
  }
  return Joiner.on(" ").join(localizedValues);
}
origin: com.haulmont.cuba/cuba-web

protected Locale resolveLocale(@Nullable Locale requestLocale) {
  Map<String, Locale> locales = globalConfig.getAvailableLocales();
  if (globalConfig.getLocaleSelectVisible()) {
    String lastLocale = getCookieValue(COOKIE_LOCALE);
    if (lastLocale != null) {
      for (Locale locale : locales.values()) {
        if (locale.toLanguageTag().equals(lastLocale)) {
          return locale;
        }
      }
    }
  }
  if (requestLocale != null) {
    Locale requestTrimmedLocale = messageTools.trimLocale(requestLocale);
    if (locales.containsValue(requestTrimmedLocale)) {
      return requestTrimmedLocale;
    }
    // if not found and application locale contains country, try to match by language only
    if (!StringUtils.isEmpty(requestLocale.getCountry())) {
      Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage());
      for (Locale locale : locales.values()) {
        if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) {
          return locale;
        }
      }
    }
  }
  // return default locale
  return messageTools.getDefaultLocale();
}
origin: com.haulmont.cuba/cuba-web

protected Locale resolveLocale(HttpServletRequest req, Messages messages, GlobalConfig globalConfig) {
  Map<String, Locale> locales = globalConfig.getAvailableLocales();
  if (globalConfig.getLocaleSelectVisible()) {
    String lastLocale = getLocaleFromCookie(req);
    if (lastLocale != null) {
      for (Locale locale : locales.values()) {
        if (locale.toLanguageTag().equals(lastLocale)) {
          return locale;
        }
      }
    }
  }
  Locale requestLocale = req.getLocale();
  if (requestLocale != null) {
    Locale requestTrimmedLocale = messages.getTools().trimLocale(requestLocale);
    if (locales.containsValue(requestTrimmedLocale)) {
      return requestTrimmedLocale;
    }
    // if not found and application locale contains country, try to match by language only
    if (!StringUtils.isEmpty(requestLocale.getCountry())) {
      Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage());
      for (Locale locale : locales.values()) {
        if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) {
          return locale;
        }
      }
    }
  }
  return messages.getTools().getDefaultLocale();
}
origin: com.haulmont.cuba/cuba-gui

protected void createLanguageLookup() {
  languageLookup = uiComponents.create(LookupField.TYPE_STRING);
  FieldGroup.FieldConfig languageLookupFc = fieldGroupRight.getFieldNN("language");
  languageLookup.setDatasource(languageLookupFc.getTargetDatasource(), languageLookupFc.getProperty());
  languageLookup.setRequired(false);
  Map<String, Locale> locales = configuration.getConfig(GlobalConfig.class).getAvailableLocales();
  Map<String, String> options = new TreeMap<>();
  for (Map.Entry<String, Locale> entry : locales.entrySet()) {
    options.put(entry.getKey(), messages.getTools().localeToString(entry.getValue()));
  }
  languageLookup.setOptionsMap(options);
  languageLookupFc.setComponent(languageLookup);
}
origin: com.haulmont.cuba/cuba-gui

protected void initLocalizedFrame() {
  if (globalConfig.getAvailableLocales().size() > 1) {
    tabsheet.getTab("localization").setVisible(true);
    localizedFrame = (LocalizedNameFrame) openFrame(
        tabsheet.getTabComponent("localization"), "localizedNameFrame");
    localizedFrame.setWidth("100%");
    localizedFrame.setHeight("250px");
  }
}
origin: com.haulmont.cuba/cuba-gui

protected void initLocalizedFrame() {
  if (globalConfig.getAvailableLocales().size() > 1) {
    localizedGroupBox.setVisible(true);
    localizedFrame = (LocalizedNameFrame) openFrame(localizedGroupBox, "localizedNameFrame");
    localizedFrame.setWidth("100%");
    localizedFrame.setHeight(AUTO_SIZE);
    localizedFrame.setValue(category.getLocaleNames());
  }
}
origin: com.haulmont.cuba/cuba-global

} else {
  try {
    Map<String, Locale> availableLocales = configuration.getConfig(GlobalConfig.class).getAvailableLocales();
    Locale defaultLocale = availableLocales.values().iterator().next();
origin: com.haulmont.cuba/cuba-global

for (Locale locale : globalConfig.getAvailableLocales().values()) {
  String numberDecimalSeparator = getMainMessage("numberDecimalSeparator", locale);
  String numberGroupingSeparator = getMainMessage("numberGroupingSeparator", locale);
origin: com.haulmont.cuba/cuba-gui

protected void initLocalesField() {
  Map<String, Locale> locales = globalConfig.getAvailableLocales();
  localesSelect.setOptionsMap(locales);
  localesSelect.addValueChangeListener(createLocaleSelectValueChangeListener());
  localesSelect.setValue(userSessionSource.getLocale());
}
origin: com.haulmont.cuba/cuba-idp

Map<String, Locale> availableLocales = globalConfig.getAvailableLocales();
Locale requestedLocale = Locale.forLanguageTag(auth.getLocale());
origin: com.haulmont.cuba/cuba-web

protected void initLocales() {
  localesSelect.setOptionsMap(globalConfig.getAvailableLocales());
  localesSelect.setValue(app.getLocale());
  boolean localeSelectVisible = globalConfig.getLocaleSelectVisible();
  localesSelect.setVisible(localeSelectVisible);
  // if old layout is used
  Component localesSelectLabel = getComponent("localesSelectLabel");
  if (localesSelectLabel != null) {
    localesSelectLabel.setVisible(localeSelectVisible);
  }
  localesSelect.addValueChangeListener(e -> {
    Locale selectedLocale = (Locale) e.getValue();
    app.setLocale(selectedLocale);
    authInfoThreadLocal.set(new AuthInfo(loginField.getValue(), passwordField.getValue(),
        rememberMeCheckBox.getValue()));
    try {
      app.createTopLevelWindow();
    } finally {
      authInfoThreadLocal.set(null);
    }
  });
}
origin: com.haulmont.cuba/cuba-core

if (!globalConfig.getAvailableLocales().containsValue(requestLocale)) {
  requestLocale = null;
origin: com.haulmont.cuba/cuba-web

Map<String, Locale> locales = globalConfig.getAvailableLocales();
TreeMap<String, String> options = new TreeMap<>();
for (Map.Entry<String, Locale> entry : locales.entrySet()) {
com.haulmont.cuba.core.globalGlobalConfiggetAvailableLocales

Javadoc

Supported locales. List of locales is shown on user login.

Popular methods of GlobalConfig

  • getConfDir
  • getWebHostName
  • getWebPort
  • getWebAppUrl
  • getWebContextName
  • getLocaleSelectVisible
    Show locale select in LoginWindow.
  • getTempDir
  • getAllowQueryFromSelected
  • getDataDir
  • getHealthCheckResponse
  • getNumberIdCacheSize
  • getRestRequiresSecurityToken
  • getNumberIdCacheSize,
  • getRestRequiresSecurityToken,
  • getTestMode,
  • getUserSessionLogEnabled,
  • getAnonymousSessionId,
  • getAppFolderEditWindowClassName,
  • getCubaClasspathDirectories,
  • getDeepCopyNonPersistentReferences,
  • getDisableEscapingLikeForDataStores

Popular in Java

  • Reading from database using SQL prepared statement
  • getApplicationContext (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • setScale (BigDecimal)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now