Search in sources :

Example 6 with Translation

use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.

the class TranslationBatchReadCache method getFromCache.

public static Translation getFromCache(TranslatedEntity entityType, String id, String propertyName, String localeCode) {
    Map<String, Translation> threadlocalCache = getThreadlocalCache();
    Translation translation = threadlocalCache.get(buildCacheKey(entityType, id, propertyName, localeCode));
    if (translation == null && StringUtils.contains(localeCode, '_')) {
        String languageWithoutCountryCode = localeCode.substring(localeCode.indexOf('_') + 1);
        translation = threadlocalCache.get(buildCacheKey(entityType, id, propertyName, languageWithoutCountryCode));
    }
    return translation;
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation)

Example 7 with Translation

use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.

the class TranslationBatchReadCache method addToCache.

public static void addToCache(List<Translation> translations) {
    long threadId = Thread.currentThread().getId();
    Map<String, Translation> threadlocalCache = getThreadlocalCache();
    if (threadlocalCache == null) {
        threadlocalCache = new HashMap<String, Translation>();
    }
    Map<String, Translation> additionalTranslations = BLCMapUtils.keyedMap(translations, new TypedClosure<String, Translation>() {

        @Override
        public String getKey(Translation translation) {
            return buildCacheKey(translation);
        }
    });
    threadlocalCache.putAll(additionalTranslations);
    getCache().put(new Element(threadId, threadlocalCache));
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) Element(net.sf.ehcache.Element)

Example 8 with Translation

use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method deleteTranslationById.

@Override
@Transactional("blTransactionManager")
public void deleteTranslationById(Long translationId) {
    Translation t = dao.readTranslationById(translationId);
    dao.delete(t);
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Translation

use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method findBestTemplateTranslation.

@Override
public Translation findBestTemplateTranslation(String specificPropertyKey, String generalPropertyKey, Map<String, Map<String, Translation>> propertyTranslationMap, String entityId) {
    Translation translation = null;
    if (propertyTranslationMap.containsKey(specificPropertyKey)) {
        Map<String, Translation> byEntity = propertyTranslationMap.get(specificPropertyKey);
        translation = byEntity.get(entityId);
    }
    if (translation == null && propertyTranslationMap.containsKey(generalPropertyKey)) {
        Map<String, Translation> byEntity = propertyTranslationMap.get(generalPropertyKey);
        translation = byEntity.get(entityId);
    }
    return translation;
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation)

Example 10 with Translation

use of org.broadleafcommerce.common.i18n.domain.Translation in project BroadleafCommerce by BroadleafCommerce.

the class TranslationServiceImpl method update.

@Override
@Transactional("blTransactionManager")
public Translation update(Long translationId, String localeCode, String translatedValue) {
    Translation t = dao.readTranslationById(translationId);
    // Check to see if there is another translation that matches this updated one. We'll remove it if it exists
    Translation t2 = dao.readTranslation(t.getEntityType(), t.getEntityId(), t.getFieldName(), localeCode);
    if (t2 != null && t != t2) {
        dao.delete(t2);
    }
    t.setLocaleCode(localeCode);
    t.setTranslatedValue(translatedValue);
    return save(t);
}
Also used : Translation(org.broadleafcommerce.common.i18n.domain.Translation) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Translation (org.broadleafcommerce.common.i18n.domain.Translation)26 TranslationImpl (org.broadleafcommerce.common.i18n.domain.TranslationImpl)8 ArrayList (java.util.ArrayList)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 StandardCacheItem (org.broadleafcommerce.common.extension.StandardCacheItem)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Element (net.sf.ehcache.Element)4 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)4 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)4 Predicate (javax.persistence.criteria.Predicate)3 TranslatedEntity (org.broadleafcommerce.common.i18n.domain.TranslatedEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)2 TranslationForm (org.broadleafcommerce.openadmin.web.form.TranslationForm)2