From 666899bb4519ee5fcad4fdf321fe4b5a091ec9c9 Mon Sep 17 00:00:00 2001 From: Axolotle Date: Tue, 14 Jul 2020 22:42:05 +0200 Subject: [PATCH] add ability to also pass a route params when needed in as a traduction variable --- app/src/components/Breadcrumb.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/components/Breadcrumb.vue b/app/src/components/Breadcrumb.vue index 0018644f..6d3f382c 100644 --- a/app/src/components/Breadcrumb.vue +++ b/app/src/components/Breadcrumb.vue @@ -9,7 +9,9 @@ :key="index" :to="{name: route.name}" :active="index == lastIndex ? true : false" - >{{ route.trad ? $t(route.trad) : params[route.param] }} + > + {{ route.text }} + @@ -20,7 +22,19 @@ export default { return this.$route.params }, breadcrumb: function () { - return this.$route.meta.breadcrumb + return this.$route.meta.breadcrumb.map(({name, trad, param}) => { + let text = '' + // if a traduction key string has been given and we also need to pass + // the route param as a variable. + if (trad && param) { + text = this.$i18n.t(trad, {[param]: this.params[param]}) + } else if (trad) { + text = this.$i18n.t(trad) + } else { + text = this.params[param] + } + return {name, text} + }) }, lastIndex: function () { return this.breadcrumb.length - 1