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 getLanguages = tech => ['en', ...tech.translations.map(t => t.locale)];
22 export const getTranslation = (tech, prop, lang) => {
23 const direct = tech.translations.find(t => t.locale === lang);
27 const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2));
29 return sameLang[prop];
34 export const compareTranslation = (prop, lang) => (a, b) =>
35 getTranslation(a, prop, lang).localeCompare(getTranslation(b, prop, lang));
37 export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18n.language));