@Service(value="blTranslationService") public class TranslationServiceImpl extends Object implements TranslationService, TranslationSupport
Modifier and Type | Field and Description |
---|---|
protected javax.cache.Cache<String,Object> |
cache |
protected javax.cache.CacheManager |
cacheManager |
protected TranslationDao |
dao |
protected TranslationServiceExtensionManager |
extensionManager |
protected LocaleService |
localeService |
protected static org.apache.commons.logging.Log |
LOG |
protected boolean |
returnBlankTranslationForNotDefaultLocale |
protected SandBoxHelper |
sandBoxHelper |
protected StatisticsService |
statisticsService |
protected List<TranslationOverrideStrategy> |
strategies |
protected int |
templateThresholdForFullCache
The default is 1000.
|
protected int |
thresholdForFullCache
The default is 1000.
|
protected List<String> |
translationExceptionProperties |
Constructor and Description |
---|
TranslationServiceImpl() |
Modifier and Type | Method and Description |
---|---|
void |
deleteTranslationById(Long translationId)
Deletes the given translations
|
List<Translation> |
findAllTranslationEntries(TranslatedEntity translatedEntity,
ResultType standard,
List<String> entityIds)
Find all the available translations for the given params.
|
Translation |
findBestTemplateTranslation(String specificPropertyKey,
String generalPropertyKey,
Map<String,Map<String,Translation>> propertyTranslationMap,
String entityId)
Find the most appropriate translation in the map.
|
Translation |
findTranslationById(Long id)
Find a translation instance by its primary key value.
|
TranslatedEntity |
getAssignableEntityType(String className)
Gets the TranslatedEntity based on the passed className.
|
javax.cache.Cache<String,Object> |
getCache()
Get the translation specific cache (different than the level-2 hibernate cache)
|
String |
getCacheKey(ResultType resultType,
TranslatedEntity entityType)
Build a cache key
|
List<String> |
getCacheKeyListForTemplateSite(String propertyName)
Returns a list of cacheKeys for a template site
|
protected String |
getCacheName() |
String |
getDefaultTranslationValue(Object entity,
String property,
Locale locale,
String requestedDefaultValue)
Intended for use with the
DynamicTranslationProvider 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 |
getTemplateThresholdForFullCache()
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 |
getThresholdForFullCache()
Retrieve the threshold under which the full list of standard site translation overrides are cached.
|
String |
getTranslatedValue(Object entity,
String property,
Locale locale)
Returns the translated value of the property for the given entity.
|
Translation |
getTranslation(TranslatedEntity entity,
String entityId,
String fieldName,
String localeCode)
Attempts to find the translation object for the given parameters
|
List<Translation> |
getTranslations(String ceilingEntityClassname,
String entityId,
String property)
Finds all current translations for the specified field
|
protected boolean |
localeMatchesDefaultLocale(Locale locale)
Returns true if the passed in locale's language matches the Broadleaf default locale.
|
StandardCacheItem |
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 defaultLocaleExceptionList
The default implementation checks the "translationExceptionProperties" list to see if the
property matches one of the regularExpressions in that list.
|
void |
removeTranslationFromCache(Translation translation)
Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)
|
protected String |
replaceEmptyWithNullResponse(String response) |
Translation |
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.
|
Translation |
save(Translation translation)
Persists the given translation
|
void |
setTemplateThresholdForFullCache(int templateThresholdForFullCache) |
void |
setThresholdForFullCache(int thresholdForFullCache) |
protected boolean |
shouldTranslateLocale(String localeCode)
Whether translations should be gathered for the provided locale.
|
Translation |
update(Long translationId,
String localeCode,
String translatedValue)
Updates the given translation id with the new locale code and translated value
|
protected static final org.apache.commons.logging.Log LOG
protected TranslationDao dao
protected StatisticsService statisticsService
protected SandBoxHelper sandBoxHelper
protected TranslationServiceExtensionManager extensionManager
@Value(value="${translation.thresholdForFullCache:1000}") protected int thresholdForFullCache
@Value(value="${translation.thresholdForFullCache:1000}") protected int templateThresholdForFullCache
TranslationSupport.getTemplateThresholdForFullCache()
@Value(value="${returnBlankTranslationForNotDefaultLocale:false}") protected boolean returnBlankTranslationForNotDefaultLocale
protected LocaleService localeService
protected List<TranslationOverrideStrategy> strategies
protected javax.cache.CacheManager cacheManager
@Transactional(value="blTransactionManager") public Translation save(Translation translation)
TranslationService
save
in interface TranslationService
@Transactional(value="blTransactionManager") public Translation save(String entityType, String entityId, String fieldName, String localeCode, String translatedValue)
TranslationService
save
in interface TranslationService
public Translation findTranslationById(Long id)
TranslationService
findTranslationById
in interface TranslationService
id
- the primary key value@Transactional(value="blTransactionManager") public Translation update(Long translationId, String localeCode, String translatedValue)
TranslationService
update
in interface TranslationService
@Transactional(value="blTransactionManager") public void deleteTranslationById(Long translationId)
TranslationService
deleteTranslationById
in interface TranslationService
public Translation getTranslation(TranslatedEntity entity, String entityId, String fieldName, String localeCode)
TranslationService
getTranslation
in interface TranslationService
public List<Translation> getTranslations(String ceilingEntityClassname, String entityId, String property)
TranslationService
getTranslations
in interface TranslationService
public javax.cache.Cache<String,Object> getCache()
TranslationService
getCache
in interface TranslationService
getCache
in interface TranslationSupport
protected String getCacheName()
public String getTranslatedValue(Object entity, String property, Locale locale)
TranslationService
getTranslatedValue
in interface TranslationService
protected boolean shouldTranslateLocale(String localeCode)
localeCode
- public void removeTranslationFromCache(Translation translation)
TranslationService
removeTranslationFromCache
in interface TranslationService
translation
- The translation instance to removeprotected String getOverrideTranslatedValue(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode)
protected String getTemplateTranslatedValue(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey)
public StandardCacheItem lookupTranslationFromMap(String key, Map<String,Map<String,StandardCacheItem>> propertyTranslationMap, String entityId)
TranslationSupport
lookupTranslationFromMap
in interface TranslationSupport
public Translation findBestTemplateTranslation(String specificPropertyKey, String generalPropertyKey, Map<String,Map<String,Translation>> propertyTranslationMap, String entityId)
TranslationSupport
findBestTemplateTranslation
in interface TranslationSupport
protected TranslatedEntity getEntityType(Class<?> entityClass)
protected TranslatedEntity getEntityType(Object entity)
public TranslatedEntity getAssignableEntityType(String className)
TranslationService
getAssignableEntityType
in interface TranslationService
public String getCacheKey(ResultType resultType, TranslatedEntity entityType)
TranslationSupport
getCacheKey
in interface TranslationSupport
public List<String> getCacheKeyListForTemplateSite(String propertyName)
TranslationSupport
getCacheKeyListForTemplateSite
in interface TranslationSupport
public int getThresholdForFullCache()
TranslationSupport
thresholdForFullCache
for more information on setting the value.getThresholdForFullCache
in interface TranslationSupport
public void setThresholdForFullCache(int thresholdForFullCache)
setThresholdForFullCache
in interface TranslationSupport
public int getTemplateThresholdForFullCache()
TranslationSupport
templateThresholdForFullCache
for more information on setting the value.getTemplateThresholdForFullCache
in interface TranslationSupport
public void setTemplateThresholdForFullCache(int templateThresholdForFullCache)
setTemplateThresholdForFullCache
in interface TranslationSupport
public String getDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue)
TranslationService
DynamicTranslationProvider
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.getDefaultTranslationValue
in interface TranslationService
public List<Translation> findAllTranslationEntries(TranslatedEntity translatedEntity, ResultType standard, List<String> entityIds)
TranslationService
findAllTranslationEntries
in interface TranslationService
entityIds
- the Translation.getEntityId()
to restrict the results byprotected boolean propertyInDefaultLocaleExceptionList(Object entity, String property)
entity
- property
- protected boolean localeMatchesDefaultLocale(Locale locale)
locale
- Copyright © 2022. All rights reserved.