X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FTechnique.js;h=7388ccb97bb5c3d7cb8816277a4e340235eef0f8;hb=7c6716036321ba09846785720e81459aad55a323;hp=410f01595657de34f339d8c0f88b529bbdab316c;hpb=0586e04204885088f31ac9861446eb0759cc8d2f;p=alttp.git diff --git a/resources/js/helpers/Technique.js b/resources/js/helpers/Technique.js index 410f015..7388ccb 100644 --- a/resources/js/helpers/Technique.js +++ b/resources/js/helpers/Technique.js @@ -1,5 +1,21 @@ import i18n from '../i18n'; +export const getLink = tech => { + if (tech.type === 'dungeon') { + return `/dungeons/${tech.name}`; + } + if (tech.type === 'location') { + return `/locations/${tech.name}`; + } + if (tech.type === 'mode') { + return `/modes/${tech.name}`; + } + if (tech.type === 'ruleset') { + return `/rulesets/${tech.name}`; + } + return `/tech/${tech.name}`; +}; + export const getRelations = (tech, type) => { const rs = (tech && tech.relations) || []; return type ? rs.filter(r => r && r.pivot && r.pivot.type === type) : rs; @@ -7,7 +23,22 @@ export const getRelations = (tech, type) => { export const hasRelations = (tech, type) => getRelations(tech, type).length > 0; +export const getLanguages = tech => ['en', ...tech.translations.map(t => t.locale)]; + +export const getMatchedLocale = (tech, lang) => { + const direct = tech.translations.find(t => t.locale === lang); + if (direct) { + return direct.locale; + } + const sameLang = tech.translations.find(t => t.locale.substr(0, 2) === lang.substr(0, 2)); + if (sameLang) { + return sameLang.locale; + } + return 'en'; +}; + export const getTranslation = (tech, prop, lang) => { + if (!tech) return ''; const direct = tech.translations.find(t => t.locale === lang); if (direct) { return direct[prop]; @@ -26,6 +57,7 @@ export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18 export default { compareTranslation, + getLanguages, getRelations, getTranslation, hasRelations,