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;
}
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));
}
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);
}
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;
}
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);
}
Aggregations