Class TranslationServiceImpl
- All Implemented Interfaces:
TranslationService,TranslationSupport
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected javax.cache.CacheManagerprotected TranslationDaoprotected TranslationServiceExtensionManagerprotected LocaleServiceprotected static final org.apache.commons.logging.Logprotected booleanprotected SandBoxHelperprotected StatisticsServiceprotected List<TranslationOverrideStrategy>protected intThe default is 1000.protected intThe default is 1000. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteTranslationById(Long translationId) Deletes the given translationsfindAllTranslationEntries(TranslatedEntity translatedEntity, ResultType standard, List<String> entityIds) Find all the available translations for the given params.findBestTemplateTranslation(String specificPropertyKey, String generalPropertyKey, Map<String, Map<String, Translation>> propertyTranslationMap, String entityId) Find the most appropriate translation in the map.Find a translation instance by its primary key value.getAssignableEntityType(String className) Gets the TranslatedEntity based on the passed className.getCache()Get the translation specific cache (different than the level-2 hibernate cache)getCacheKey(ResultType resultType, TranslatedEntity entityType) Build a cache keygetCacheKeyListForTemplateSite(String propertyName) Returns a list of cacheKeys for a template siteprotected StringgetDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue) Intended for use with theDynamicTranslationProviderto determine the default value when a translation was not provided.protected TranslatedEntitygetEntityType(Class<?> entityClass) protected TranslatedEntitygetEntityType(Object entity) protected StringgetOverrideTranslatedValue(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode) intRetrieve the threshold under which the full list of template catalog translations are cached.protected StringgetTemplateTranslatedValue(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) intRetrieve the threshold under which the full list of standard site translation overrides are cached.getTranslatedValue(Object entity, String property, Locale locale) Returns the translated value of the property for the given entity.getTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode) Attempts to find the translation object for the given parametersgetTranslations(String ceilingEntityClassname, String entityId, String property) Finds all current translations for the specified fieldprotected booleanlocaleMatchesDefaultLocale(Locale locale) Returns true if the passed in locale's language matches the Broadleaf default locale.lookupTranslationFromMap(String key, Map<String, Map<String, StandardCacheItem>> propertyTranslationMap, String entityId) Retrieve a cached translation from an individual property translation map retrieved from the cache.protected booleanpropertyInDefaultLocaleExceptionList(Object entity, String property) Returns true if the passed in entity / property combination is in the defaultLocaleExceptionListvoidremoveTranslationFromCache(Translation translation) Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)protected StringreplaceEmptyWithNullResponse(String response) save(String entityType, String entityId, String fieldName, String localeCode, String translatedValue) Creates a new translation object for the requested parameters, saves it, and returns the saved instance.save(Translation translation) Persists the given translationvoidsetTemplateThresholdForFullCache(int templateThresholdForFullCache) voidsetThresholdForFullCache(int thresholdForFullCache) protected booleanshouldTranslateLocale(String localeCode) Whether translations should be gathered for the provided locale.Updates the given translation id with the new locale code and translated value
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
dao
-
statisticsService
-
sandBoxHelper
-
extensionManager
-
thresholdForFullCache
@Value("${translation.thresholdForFullCache:1000}") protected int thresholdForFullCacheThe default is 1000. Use the 'translation.thresholdForFullCache' to change the value. -
templateThresholdForFullCache
@Value("${translation.thresholdForFullCache:1000}") protected int templateThresholdForFullCacheThe default is 1000. This property also uses 'translation.thresholdForFullCache' for backwards compatibility. If you wish to change this value, you'll need to extend TranslationServiceImpl and return a custom value forTranslationSupport.getTemplateThresholdForFullCache() -
returnBlankTranslationForNotDefaultLocale
@Value("${returnBlankTranslationForNotDefaultLocale:false}") protected boolean returnBlankTranslationForNotDefaultLocale -
translationExceptionProperties
-
localeService
-
strategies
-
cacheManager
protected javax.cache.CacheManager cacheManager -
cache
-
-
Constructor Details
-
TranslationServiceImpl
public TranslationServiceImpl()
-
-
Method Details
-
save
Description copied from interface:TranslationServicePersists the given translation- Specified by:
savein interfaceTranslationService- Returns:
- the persisted translation
-
save
@Transactional("blTransactionManager") public Translation save(String entityType, String entityId, String fieldName, String localeCode, String translatedValue) Description copied from interface:TranslationServiceCreates a new translation object for the requested parameters, saves it, and returns the saved instance. Note: This method will overwrite a previously existing translation if it matches on entityType, entityId, fieldName, and localeCode.- Specified by:
savein interfaceTranslationService- Returns:
- the persisted translation
-
findTranslationById
Description copied from interface:TranslationServiceFind a translation instance by its primary key value.- Specified by:
findTranslationByIdin interfaceTranslationService- Parameters:
id- the primary key value- Returns:
-
update
@Transactional("blTransactionManager") public Translation update(Long translationId, String localeCode, String translatedValue) Description copied from interface:TranslationServiceUpdates the given translation id with the new locale code and translated value- Specified by:
updatein interfaceTranslationService- Returns:
- the persisted translation
-
deleteTranslationById
Description copied from interface:TranslationServiceDeletes the given translations- Specified by:
deleteTranslationByIdin interfaceTranslationService
-
getTranslation
public Translation getTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode) Description copied from interface:TranslationServiceAttempts to find the translation object for the given parameters- Specified by:
getTranslationin interfaceTranslationService- Returns:
- the persisted translation
-
getTranslations
public List<Translation> getTranslations(String ceilingEntityClassname, String entityId, String property) Description copied from interface:TranslationServiceFinds all current translations for the specified field- Specified by:
getTranslationsin interfaceTranslationService- Returns:
- the list of translations
-
getCache
Description copied from interface:TranslationServiceGet the translation specific cache (different than the level-2 hibernate cache)- Specified by:
getCachein interfaceTranslationService- Specified by:
getCachein interfaceTranslationSupport- Returns:
- the translation specific cache
-
getCacheName
-
getTranslatedValue
Description copied from interface:TranslationServiceReturns the translated value of the property for the given entity. For example, if entity is an instance of Product and property is equal to name, this method might return "Hoppin' Hot Sauce" if we are in an English locale and "Salsa de la Muerte Saltante" if we are in a Spanish locale.If a country is set on the locale (locale code en_GB for example), we will first look for a translation that matches en_GB, and then look for a translation for en. If a translated value for the given locale is not available, it will return null.
- Specified by:
getTranslatedValuein interfaceTranslationService- Returns:
- the translated value of the property for the given entity
-
shouldTranslateLocale
Whether translations should be gathered for the provided locale.- Parameters:
localeCode-- Returns:
- Whether translations should be gathered for the provided locale.
-
removeTranslationFromCache
Description copied from interface:TranslationServiceRemove a translation instance from the translation specific cache (different than level-2 hibernate cache)- Specified by:
removeTranslationFromCachein interfaceTranslationService- Parameters:
translation- The translation instance to remove
-
getOverrideTranslatedValue
-
replaceEmptyWithNullResponse
-
getTemplateTranslatedValue
-
lookupTranslationFromMap
public StandardCacheItem lookupTranslationFromMap(String key, Map<String, Map<String, StandardCacheItem>> propertyTranslationMap, String entityId) Description copied from interface:TranslationSupportRetrieve a cached translation from an individual property translation map retrieved from the cache.- Specified by:
lookupTranslationFromMapin interfaceTranslationSupport- Returns:
-
findBestTemplateTranslation
public Translation findBestTemplateTranslation(String specificPropertyKey, String generalPropertyKey, Map<String, Map<String, Translation>> propertyTranslationMap, String entityId) Description copied from interface:TranslationSupportFind the most appropriate translation in the map. The most specific qualified translation will win.- Specified by:
findBestTemplateTranslationin interfaceTranslationSupport- Returns:
-
getEntityType
-
getEntityType
-
getAssignableEntityType
Description copied from interface:TranslationServiceGets the TranslatedEntity based on the passed className. The TranslatedEntity may be an assignable.- Specified by:
getAssignableEntityTypein interfaceTranslationService- Returns:
-
getCacheKey
Description copied from interface:TranslationSupportBuild a cache key- Specified by:
getCacheKeyin interfaceTranslationSupport- Returns:
-
getCacheKeyListForTemplateSite
Description copied from interface:TranslationSupportReturns a list of cacheKeys for a template site- Specified by:
getCacheKeyListForTemplateSitein interfaceTranslationSupport- Returns:
-
getThresholdForFullCache
public int getThresholdForFullCache()Description copied from interface:TranslationSupportRetrieve the threshold under which the full list of standard site translation overrides are cached. SeethresholdForFullCachefor more information on setting the value.- Specified by:
getThresholdForFullCachein interfaceTranslationSupport- Returns:
-
setThresholdForFullCache
public void setThresholdForFullCache(int thresholdForFullCache) - Specified by:
setThresholdForFullCachein interfaceTranslationSupport
-
getTemplateThresholdForFullCache
public int getTemplateThresholdForFullCache()Description copied from interface:TranslationSupportRetrieve the threshold under which the full list of template catalog translations are cached. SeetemplateThresholdForFullCachefor more information on setting the value.- Specified by:
getTemplateThresholdForFullCachein interfaceTranslationSupport- Returns:
-
setTemplateThresholdForFullCache
public void setTemplateThresholdForFullCache(int templateThresholdForFullCache) - Specified by:
setTemplateThresholdForFullCachein interfaceTranslationSupport
-
getDefaultTranslationValue
public String getDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue) Description copied from interface:TranslationServiceIntended for use with theDynamicTranslationProviderto determine the default value when a translation was not provided.The default implementation of this method relies on a system property "returnBlankTranslationForNotDefaultLocale". If this is true, the system will return blank if the language of the defaultLocale does not match the language of the passed in locale.
For example, consider the "longDescription" property and the system default locale is "en". If this method is called for a locale of "en_CA", the requestedDefaultValue will be returned. If the method is called with a value of "fr_CA", blank will be returned.
- Specified by:
getDefaultTranslationValuein interfaceTranslationService- Returns:
-
findAllTranslationEntries
public List<Translation> findAllTranslationEntries(TranslatedEntity translatedEntity, ResultType standard, List<String> entityIds) Description copied from interface:TranslationServiceFind all the available translations for the given params.- Specified by:
findAllTranslationEntriesin interfaceTranslationServicestandard- param drives whether to look for entries at a template level or standard site level (multitenant concepts). Can be IGNORE. Any multitenant behavior is ignored in the absence of the multitenant module.entityIds- theTranslation.getEntityId()to restrict the results by- Returns:
-
propertyInDefaultLocaleExceptionList
Returns true if the passed in entity / property combination is in the defaultLocaleExceptionListThe default implementation checks the "translationExceptionProperties" list to see if the property matches one of the regularExpressions in that list.
Implementors are expected to override this method for implementation specific needs.
- Parameters:
entity-property-- Returns:
-
localeMatchesDefaultLocale
Returns true if the passed in locale's language matches the Broadleaf default locale.- Parameters:
locale-- Returns:
-