Class TranslationServiceImpl
- All Implemented Interfaces:
TranslationService
,TranslationSupport
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected javax.cache.CacheManager
protected TranslationDao
protected TranslationServiceExtensionManager
protected LocaleService
protected static final org.apache.commons.logging.Log
protected boolean
protected SandBoxHelper
protected StatisticsService
protected List<TranslationOverrideStrategy>
protected int
The default is 1000.protected int
The default is 1000. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteTranslationById
(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 String
getDefaultTranslationValue
(Object entity, String property, Locale locale, String requestedDefaultValue) Intended for use with theDynamicTranslationProvider
to determine the default value when a translation was not provided.protected TranslatedEntity
getEntityType
(Class<?> entityClass) protected TranslatedEntity
getEntityType
(Object entity) protected String
getOverrideTranslatedValue
(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode) int
Retrieve the threshold under which the full list of template catalog translations are cached.protected String
getTemplateTranslatedValue
(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey) int
Retrieve 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 boolean
localeMatchesDefaultLocale
(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 boolean
propertyInDefaultLocaleExceptionList
(Object entity, String property) Returns true if the passed in entity / property combination is in the defaultLocaleExceptionListvoid
removeTranslationFromCache
(Translation translation) Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)protected String
replaceEmptyWithNullResponse
(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 translationvoid
setTemplateThresholdForFullCache
(int templateThresholdForFullCache) void
setThresholdForFullCache
(int thresholdForFullCache) protected boolean
shouldTranslateLocale
(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:TranslationService
Persists the given translation- Specified by:
save
in 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:TranslationService
Creates 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:
save
in interfaceTranslationService
- Returns:
- the persisted translation
-
findTranslationById
Description copied from interface:TranslationService
Find a translation instance by its primary key value.- Specified by:
findTranslationById
in interfaceTranslationService
- Parameters:
id
- the primary key value- Returns:
-
update
@Transactional("blTransactionManager") public Translation update(Long translationId, String localeCode, String translatedValue) Description copied from interface:TranslationService
Updates the given translation id with the new locale code and translated value- Specified by:
update
in interfaceTranslationService
- Returns:
- the persisted translation
-
deleteTranslationById
Description copied from interface:TranslationService
Deletes the given translations- Specified by:
deleteTranslationById
in interfaceTranslationService
-
getTranslation
public Translation getTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode) Description copied from interface:TranslationService
Attempts to find the translation object for the given parameters- Specified by:
getTranslation
in interfaceTranslationService
- Returns:
- the persisted translation
-
getTranslations
public List<Translation> getTranslations(String ceilingEntityClassname, String entityId, String property) Description copied from interface:TranslationService
Finds all current translations for the specified field- Specified by:
getTranslations
in interfaceTranslationService
- Returns:
- the list of translations
-
getCache
Description copied from interface:TranslationService
Get the translation specific cache (different than the level-2 hibernate cache)- Specified by:
getCache
in interfaceTranslationService
- Specified by:
getCache
in interfaceTranslationSupport
- Returns:
- the translation specific cache
-
getCacheName
-
getTranslatedValue
Description copied from interface:TranslationService
Returns 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:
getTranslatedValue
in 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:TranslationService
Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)- Specified by:
removeTranslationFromCache
in 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:TranslationSupport
Retrieve a cached translation from an individual property translation map retrieved from the cache.- Specified by:
lookupTranslationFromMap
in interfaceTranslationSupport
- Returns:
-
findBestTemplateTranslation
public Translation findBestTemplateTranslation(String specificPropertyKey, String generalPropertyKey, Map<String, Map<String, Translation>> propertyTranslationMap, String entityId) Description copied from interface:TranslationSupport
Find the most appropriate translation in the map. The most specific qualified translation will win.- Specified by:
findBestTemplateTranslation
in interfaceTranslationSupport
- Returns:
-
getEntityType
-
getEntityType
-
getAssignableEntityType
Description copied from interface:TranslationService
Gets the TranslatedEntity based on the passed className. The TranslatedEntity may be an assignable.- Specified by:
getAssignableEntityType
in interfaceTranslationService
- Returns:
-
getCacheKey
Description copied from interface:TranslationSupport
Build a cache key- Specified by:
getCacheKey
in interfaceTranslationSupport
- Returns:
-
getCacheKeyListForTemplateSite
Description copied from interface:TranslationSupport
Returns a list of cacheKeys for a template site- Specified by:
getCacheKeyListForTemplateSite
in interfaceTranslationSupport
- Returns:
-
getThresholdForFullCache
public int getThresholdForFullCache()Description copied from interface:TranslationSupport
Retrieve the threshold under which the full list of standard site translation overrides are cached. SeethresholdForFullCache
for more information on setting the value.- Specified by:
getThresholdForFullCache
in interfaceTranslationSupport
- Returns:
-
setThresholdForFullCache
public void setThresholdForFullCache(int thresholdForFullCache) - Specified by:
setThresholdForFullCache
in interfaceTranslationSupport
-
getTemplateThresholdForFullCache
public int getTemplateThresholdForFullCache()Description copied from interface:TranslationSupport
Retrieve the threshold under which the full list of template catalog translations are cached. SeetemplateThresholdForFullCache
for more information on setting the value.- Specified by:
getTemplateThresholdForFullCache
in interfaceTranslationSupport
- Returns:
-
setTemplateThresholdForFullCache
public void setTemplateThresholdForFullCache(int templateThresholdForFullCache) - Specified by:
setTemplateThresholdForFullCache
in interfaceTranslationSupport
-
getDefaultTranslationValue
public String getDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue) Description copied from interface:TranslationService
Intended for use with theDynamicTranslationProvider
to 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:
getDefaultTranslationValue
in interfaceTranslationService
- Returns:
-
findAllTranslationEntries
public List<Translation> findAllTranslationEntries(TranslatedEntity translatedEntity, ResultType standard, List<String> entityIds) Description copied from interface:TranslationService
Find all the available translations for the given params.- Specified by:
findAllTranslationEntries
in interfaceTranslationService
standard
- 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:
-