1 import i18n from '../i18n';
3 export const getLink = tech => {
4 if (tech.type === 'mode') {
5 return `/modes/${tech.name}`;
7 if (tech.type === 'ruleset') {
8 return `/rulesets/${tech.name}`;
10 return `/tech/${tech.name}`;
13 export const getRelations = (tech, type) => {
14 const rs = (tech && tech.relations) || [];
15 return type ? rs.filter(r => r && r.pivot && r.pivot.type === type) : rs;
18 export const hasRelations = (tech, type) => getRelations(tech, type).length > 0;
20 export const getTranslation = (tech, prop, lang) => {
21 const direct = tech.translations.find(t => t.locale === lang);
25 const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2));
27 return sameLang[prop];
32 export const compareTranslation = (prop, lang) => (a, b) =>
33 getTranslation(a, prop, lang).localeCompare(getTranslation(b, prop, lang));
35 export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18n.language));