bergie/VIE — Issue #80: Multi-language access for entities
Author: ruKurz
Created: 2012-02-14 14:23:10+00:00
State: open

It should be possible to access attributes of an entity by language:

function getLocalizedAttribute(entity, attrs, lang) {
if (entity && typeof entity !== "string") {
var possibleAttrs = (_.isArray(attrs)) ? attrs : [ attrs ];
for ( var p = 0; p < possibleAttrs.length; p++) {
var attr = possibleAttrs[p];
if (entity.has(attr)) {
var value = entity.get(attr);
if (jQuery.isArray(value) && value.length > 0) {
for ( var i = 0; i < value.length; i++) {
if (value[i].indexOf('@' + lang) > -1) {
value = value[i];
break;
}
}
if (jQuery.isArray(value))
// if it is still an array, your language was not found
value = undefined;
}
value = (value) ? value.replace(/"/g, "").replace(/@[a-z]+/, '').trim() : value;
return value;
}
}
}
return undefined;
}