Class TranslationServiceImpl

java.lang.Object
org.broadleafcommerce.common.i18n.service.TranslationServiceImpl
All Implemented Interfaces:
TranslationService, TranslationSupport

@Service("blTranslationService") public class TranslationServiceImpl extends Object implements TranslationService, TranslationSupport
  • Field Details

    • LOG

      protected static final org.apache.commons.logging.Log LOG
    • dao

      protected TranslationDao dao
    • statisticsService

      protected StatisticsService statisticsService
    • sandBoxHelper

      protected SandBoxHelper sandBoxHelper
    • extensionManager

      protected TranslationServiceExtensionManager extensionManager
    • thresholdForFullCache

      @Value("${translation.thresholdForFullCache:1000}") protected int thresholdForFullCache
      The default is 1000. Use the 'translation.thresholdForFullCache' to change the value.
    • templateThresholdForFullCache

      @Value("${translation.thresholdForFullCache:1000}") protected int templateThresholdForFullCache
      The 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 for TranslationSupport.getTemplateThresholdForFullCache()
    • returnBlankTranslationForNotDefaultLocale

      @Value("${returnBlankTranslationForNotDefaultLocale:false}") protected boolean returnBlankTranslationForNotDefaultLocale
    • translationExceptionProperties

      protected List<String> translationExceptionProperties
    • localeService

      protected LocaleService localeService
    • strategies

      protected List<TranslationOverrideStrategy> strategies
    • cacheManager

      protected javax.cache.CacheManager cacheManager
    • cache

      protected javax.cache.Cache<String,Object> cache
  • Constructor Details

    • TranslationServiceImpl

      public TranslationServiceImpl()
  • Method Details

    • save

      @Transactional("blTransactionManager") public Translation save(Translation translation)
      Description copied from interface: TranslationService
      Persists the given translation
      Specified by:
      save in interface TranslationService
      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 interface TranslationService
      Returns:
      the persisted translation
    • findTranslationById

      public Translation findTranslationById(Long id)
      Description copied from interface: TranslationService
      Find a translation instance by its primary key value.
      Specified by:
      findTranslationById in interface TranslationService
      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 interface TranslationService
      Returns:
      the persisted translation
    • deleteTranslationById

      @Transactional("blTransactionManager") public void deleteTranslationById(Long translationId)
      Description copied from interface: TranslationService
      Deletes the given translations
      Specified by:
      deleteTranslationById in interface TranslationService
    • 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 interface TranslationService
      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 interface TranslationService
      Returns:
      the list of translations
    • getCache

      public javax.cache.Cache<String,Object> getCache()
      Description copied from interface: TranslationService
      Get the translation specific cache (different than the level-2 hibernate cache)
      Specified by:
      getCache in interface TranslationService
      Specified by:
      getCache in interface TranslationSupport
      Returns:
      the translation specific cache
    • getCacheName

      protected String getCacheName()
    • getTranslatedValue

      public String getTranslatedValue(Object entity, String property, Locale locale)
      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 interface TranslationService
      Returns:
      the translated value of the property for the given entity
    • shouldTranslateLocale

      protected boolean shouldTranslateLocale(String localeCode)
      Whether translations should be gathered for the provided locale.
      Parameters:
      localeCode -
      Returns:
      Whether translations should be gathered for the provided locale.
    • removeTranslationFromCache

      public void removeTranslationFromCache(Translation translation)
      Description copied from interface: TranslationService
      Remove a translation instance from the translation specific cache (different than level-2 hibernate cache)
      Specified by:
      removeTranslationFromCache in interface TranslationService
      Parameters:
      translation - The translation instance to remove
    • getOverrideTranslatedValue

      protected String getOverrideTranslatedValue(String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode)
    • replaceEmptyWithNullResponse

      protected String replaceEmptyWithNullResponse(String response)
    • getTemplateTranslatedValue

      protected String getTemplateTranslatedValue(String standardCacheKey, String property, TranslatedEntity entityType, String entityId, String localeCode, String localeCountryCode, String specificPropertyKey, String generalPropertyKey)
    • 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 interface TranslationSupport
      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 interface TranslationSupport
      Returns:
    • getEntityType

      protected TranslatedEntity getEntityType(Class<?> entityClass)
    • getEntityType

      protected TranslatedEntity getEntityType(Object entity)
    • getAssignableEntityType

      public TranslatedEntity getAssignableEntityType(String className)
      Description copied from interface: TranslationService
      Gets the TranslatedEntity based on the passed className. The TranslatedEntity may be an assignable.
      Specified by:
      getAssignableEntityType in interface TranslationService
      Returns:
    • getCacheKey

      public String getCacheKey(ResultType resultType, TranslatedEntity entityType)
      Description copied from interface: TranslationSupport
      Build a cache key
      Specified by:
      getCacheKey in interface TranslationSupport
      Returns:
    • getCacheKeyListForTemplateSite

      public List<String> getCacheKeyListForTemplateSite(String propertyName)
      Description copied from interface: TranslationSupport
      Returns a list of cacheKeys for a template site
      Specified by:
      getCacheKeyListForTemplateSite in interface TranslationSupport
      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. See thresholdForFullCache for more information on setting the value.
      Specified by:
      getThresholdForFullCache in interface TranslationSupport
      Returns:
    • setThresholdForFullCache

      public void setThresholdForFullCache(int thresholdForFullCache)
      Specified by:
      setThresholdForFullCache in interface TranslationSupport
    • getTemplateThresholdForFullCache

      public int getTemplateThresholdForFullCache()
      Description copied from interface: TranslationSupport
      Retrieve the threshold under which the full list of template catalog translations are cached. See templateThresholdForFullCache for more information on setting the value.
      Specified by:
      getTemplateThresholdForFullCache in interface TranslationSupport
      Returns:
    • setTemplateThresholdForFullCache

      public void setTemplateThresholdForFullCache(int templateThresholdForFullCache)
      Specified by:
      setTemplateThresholdForFullCache in interface TranslationSupport
    • getDefaultTranslationValue

      public String getDefaultTranslationValue(Object entity, String property, Locale locale, String requestedDefaultValue)
      Description copied from interface: TranslationService
      Intended for use with the 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.

      Specified by:
      getDefaultTranslationValue in interface TranslationService
      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 interface TranslationService
      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 - the Translation.getEntityId() to restrict the results by
      Returns:
    • propertyInDefaultLocaleExceptionList

      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.

      Implementors are expected to override this method for implementation specific needs.

      Parameters:
      entity -
      property -
      Returns:
    • localeMatchesDefaultLocale

      protected boolean localeMatchesDefaultLocale(Locale locale)
      Returns true if the passed in locale's language matches the Broadleaf default locale.
      Parameters:
      locale -
      Returns: