String localeCountryCode = localeCode;
if (StringUtils.isNotBlank(locale.getCountry())) {
localeCountryCode += "_" + locale.getCountry();
}
Translation translation;
// First, we'll try to look up a country language combo (en_GB), utilizing the cache
String countryCacheKey = getCacheKey(entityType, entityId, property, localeCountryCode);
Element countryValue = getCache().get(countryCacheKey);
if (countryValue != null) {
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), true);
translation = (Translation) countryValue.getObjectValue();
} else {
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), false);
translation = getTranslation(entityType, entityId, property, localeCountryCode);
if (translation == null) {
translation = new TranslationImpl();
}
getCache().put(new Element(countryCacheKey, translation));
}
// If we don't find one, let's try just the language (en), again utilizing the cache
if (translation.getTranslatedValue()==null) {
String nonCountryCacheKey = getCacheKey(entityType, entityId, property, localeCode);
Element nonCountryValue = getCache().get(nonCountryCacheKey);
if (nonCountryValue != null) {
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), true);
translation = (Translation) nonCountryValue.getObjectValue();
} else {
statisticsService.addCacheStat(CacheStatType.TRANSLATION_CACHE_HIT_RATE.toString(), false);
translation = getTranslation(entityType, entityId, property, localeCode);
if (translation == null) {
translation = new TranslationImpl();
}
getCache().put(new Element(nonCountryCacheKey, translation));
}
}
// If we have a match on a translation, use that instead of what we found on the entity.
if (StringUtils.isNotBlank(translation.getTranslatedValue())) {
return translation.getTranslatedValue();
}
return null;
}