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(); }
/** * @return a localized name of an entity. Messages pack must be located in the same package as entity. */ public String getEntityCaption(MetaClass metaClass) { return getEntityCaption(metaClass, null); }
/** * Get localized name of an entity property. Messages pack must be located in the same package as entity. * @param metaClass MetaClass containing the property * @param propertyName property's name * @return localized name */ public String getPropertyCaption(MetaClass metaClass, String propertyName) { return getPropertyCaption(metaClass, propertyName, null); }
/** * @deprecated Use {@link #getDefaultRequiredMessage(MetaClass, String)} * @return default required message for specified property. */ @Deprecated public String getDefaultRequiredMessage(MetaProperty metaProperty) { String notNullMessage = getNotNullMessage(metaProperty); if (notNullMessage != null) { return notNullMessage; } return messages.formatMessage(messages.getMainMessagePack(), "validation.required.defaultMsg", getPropertyCaption(metaProperty)); }
protected Map<String, String> getLocalizationForEntity(MetaClass metaClass) { Map<String, String> locMap = new TreeMap<>(); locMap.put(metaClass.getName(), messageTools.getEntityCaption(metaClass)); metaClass.getProperties().forEach(metaProperty -> { String msgKey = metaClass.getName() + "." + metaProperty.getName(); String msgValue = messageTools.getPropertyCaption(metaProperty); locMap.put(msgKey, msgValue); }); return locMap; }
protected Locale getCurrentLocale() { Locale locale; if (userSessionSource.checkCurrentUserSession()) { locale = userSessionSource.getLocale(); } else { locale = messages.getTools().getDefaultLocale(); } return locale; } }
@Override public String getLocCaption() { if (isBlank(caption) && !isBlank(propertyPath)) { MessageTools messageTools = AppBeans.get(MessageTools.class); String propertyCaption = messageTools.getPropertyCaption(metaClass, propertyPath); if (!isBlank(propertyCaption)) { return propertyCaption + "." + locCaption; } } else if (isNotBlank(caption)) { MessageTools messageTools = AppBeans.get(MessageTools.class); return messageTools.loadString(messagesPack, caption); } MetaPropertyPath mpp = DynamicAttributesUtils.getMetaPropertyPath(metaClass, getCategoryAttributeId()); if (mpp != null) { return DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty()).getLocaleName(); } return super.getLocCaption(); } }
String entity = exception.getEntity(); MetaClass entityClass = AppBeans.get(Metadata.NAME, Metadata.class).getClassNN(entity); String entityCaption = messages.getTools().getEntityCaption(entityClass); Locale locale = userSessionSource.getLocale(); String localeCode = messages.getTools().localeToString(locale); userCaption = localizedMessage.getLocalizedCaption(localeCode); userMessage = localizedMessage.getLocalizedMessage(localeCode);
/** * Get localized message by reference provided in the full format. * @param ref reference to message in the following format: {@code msg://message_pack/message_id} * @return localized message or input string itself if it doesn't begin with {@code msg://} */ public String loadString(String ref) { return loadString(null, ref); }
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); }
/** * @return a detailed localized name of an entity. Messages pack must be located in the same package as entity. */ public String getDetailedEntityCaption(MetaClass metaClass) { return getDetailedEntityCaption(metaClass, null); }
protected String internalGetMessage(String packs, String key, Locale locale, String defaultValue, boolean searchMainIfNotFound) { locale = messageTools.trimLocale(locale); String cacheKey = makeCacheKey(packs, key, locale, locale); String msg = strCache.get(cacheKey); if (msg != null) return msg; String notFound = notFoundCache.get(cacheKey); if (notFound != null) return defaultValue; msg = searchMessage(packs, key, locale, locale, new HashSet<>()); if (msg != null) { cache(cacheKey, msg); return msg; } if (searchMainIfNotFound) { String tmpCacheKey = makeCacheKey(mainMessagePack, key, locale, locale); msg = searchMessage(tmpCacheKey, key, locale, locale, new HashSet<>()); if (msg != null) { cache(cacheKey, msg); return msg; } } notFoundCache.put(cacheKey, key); return defaultValue; }
@Override protected Locale getUserLocale() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getLocale() : messageTools.getDefaultLocale(); }
/** * Get default required message for specified property of MetaClass. * * @param metaClass MetaClass containing the property * @param propertyName property's name * @return default required message for specified property of MetaClass */ public String getDefaultRequiredMessage(MetaClass metaClass, String propertyName) { MetaPropertyPath propertyPath = metaClass.getPropertyPath(propertyName); if (propertyPath != null) { String notNullMessage = getNotNullMessage(propertyPath.getMetaProperty()); if (notNullMessage != null) { return notNullMessage; } } return messages.formatMessage(messages.getMainMessagePack(), "validation.required.defaultMsg", getPropertyCaption(metaClass, propertyName)); }
/** * Get localized message by reference provided in the full format. * @param ref reference to message in the following format: {@code msg://message_pack/message_id} * @return localized message or input string itself if it doesn't begin with {@code msg://} */ public String loadString(String ref, Locale locale) { return loadString(null, ref, locale); }
protected void setupDefaults(StockChartGroup chart) { chart.setLanguage(messages.getTools().localeToString(userSessionSource.getLocale())); chart.setDataDateFormat(ChartJsonSerializationContext.DEFAULT_JS_DATE_FORMAT); }
protected void initMetaClassLookup() { Map<String, String> metaClassesOptionsMap = new TreeMap<>(); Collection<MetaClass> classes = metadata.getSession().getClasses(); for (MetaClass clazz : classes) { if (!metadata.getTools().isSystemLevel(clazz)) { String caption = messages.getTools().getDetailedEntityCaption(clazz); metaClassesOptionsMap.put(caption, clazz.getName()); } } metaClass.setOptionsMap(metaClassesOptionsMap); }
messageTools.trimLocale(locale), new FormatStrings( numberDecimalSeparator.charAt(0),
public String getDescription() { MessageTools messageTools = AppBeans.get(MessageTools.NAME); String result = messageTools.getEntityCaption(meta); return result == null ? "" : result; }
/** * Get localized name of an entity property. Messages pack must be located in the same package as entity. * * @param property MetaProperty * @return localized name */ public String getPropertyCaption(MetaProperty property) { return getPropertyCaption(property, null); }