1 import i18n from '../i18n';
3 export const getLink = tech => {
4 if (tech.type === 'dungeon') {
5 return `/dungeons/${tech.name}`;
7 if (tech.type === 'location') {
8 return `/locations/${tech.name}`;
10 if (tech.type === 'mode') {
11 return `/modes/${tech.name}`;
13 if (tech.type === 'ruleset') {
14 return `/rulesets/${tech.name}`;
16 return `/tech/${tech.name}`;
19 export const getRelations = (tech, type) => {
20 const rs = (tech && tech.relations) || [];
21 return type ? rs.filter(r => r && r.pivot && r.pivot.type === type) : rs;
24 export const hasRelations = (tech, type) => getRelations(tech, type).length > 0;
26 export const getLanguages = tech => ['en', ...tech.translations.map(t => t.locale)];
28 export const getMatchedLocale = (tech, lang) => {
29 const direct = tech.translations.find(t => t.locale === lang);
33 const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2));
35 return sameLang.locale;
40 export const getTranslation = (tech, prop, lang) => {
42 const direct = tech.translations.find(t => t.locale === lang);
46 const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2));
48 return sameLang[prop];
53 export const compareTranslation = (prop, lang) => (a, b) =>
54 getTranslation(a, prop, lang).localeCompare(getTranslation(b, prop, lang));
56 export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18n.language));