datocms-client
Version:
For new DatoCMS users, we recommend @datocms/cma-client-node
22 lines (18 loc) • 637 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = localizedRead;
function localizedRead(entity, key, localized, i18n) {
var hash = entity[key];
if (localized && hash) {
var fallbacks = i18n.fallbacks || {};
var locales = [i18n.locale].concat(fallbacks[i18n.locale] || []);
var localeWithValue = locales.find(function (locale) {
var localeValue = hash[locale];
return localeValue !== null && localeValue !== undefined && localeValue !== '' && localeValue.length !== 0;
});
return localeWithValue ? hash[localeWithValue] : null;
}
return hash;
}