huridocs/uwazi

View on GitHub
app/shared/translate.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
/** @format */

export function getLocaleTranslation(translations, locale) {
  return translations.find(d => d.locale === locale) || { contexts: [] };
}

export function getContext(translation, contextId = '') {
  return (
    translation.contexts.find(ctx => ctx.id.toString() === contextId.toString()) || { values: {} }
  );
}

export default function translate(context, key, text) {
  return context.values[key] || text;
}