1 import i18n from '../i18n';
3 export const getRelations = (tech, type) => {
4 const rs = (tech && tech.relations) || [];
5 return type ? rs.filter(r => r && r.pivot && r.pivot.type === type) : rs;
8 export const hasRelations = (tech, type) => getRelations(tech, type).length > 0;
10 export const getTranslation = (tech, prop, lang) => {
11 const direct = tech.translations.find(t => t.locale === lang);
15 const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2));
17 return sameLang[prop];
22 export const compareTranslation = (prop, lang) => (a, b) =>
23 getTranslation(a, prop, lang).localeCompare(getTranslation(b, prop, lang));
25 export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18n.language));