Skip to content

Commit

Permalink
feat(l10n): change OFF url depending on user locale (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 15, 2024
1 parent a4d92ae commit 49af006
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<i18n-t keypath="Footer.TagLine" tag="span">
<template #name>{{ APP_NAME }}</template>
<template #url>
<a href="https://world.openfoodfacts.org" target="_blank">{{ OFF_NAME }}</a>
<OpenFoodFactsLink display="link"></OpenFoodFactsLink>
</template>
</i18n-t>
</v-col>
Expand All @@ -19,9 +19,13 @@
</template>

<script>
import { defineAsyncComponent } from 'vue'
import constants from '../constants'
export default {
components: {
'OpenFoodFactsLink': defineAsyncComponent(() => import('../components/OpenFoodFactsLink.vue')),
},
data() {
return {
APP_NAME: constants.APP_NAME,
Expand Down
14 changes: 11 additions & 3 deletions src/components/OpenFoodFactsLink.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a v-if="display === 'link'" href="https://world.openfoodfacts.org" target="_blank">
<a v-if="display === 'link'" :href="getOFFUrl()" target="_blank">
{{ getOFFName() }}
</a>
<v-btn v-if="display === 'button'" size="small" append-icon="mdi-open-in-new" :href="getOFFUrl()" target="_blank">
Expand All @@ -8,6 +8,8 @@
</template>

<script>
import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import constants from '../constants'
export default {
Expand All @@ -29,12 +31,18 @@ export default {
OFF_URL: constants.OFF_URL,
}
},
computed: {
...mapStores(useAppStore),
getOFFUrlWithLocale() {
return this.OFF_URL.replace('world', this.appStore.user.language)
}
},
methods: {
getOFFUrl() {
if (this.facet && this.value) {
return `${this.OFF_URL}/${this.facet}/${this.value}`
return `${this.getOFFUrlWithLocale}/${this.facet}/${this.value}`
}
return this.OFF_URL
return this.getOFFUrlWithLocale
},
getOFFName() {
if (this.action === 'add') {
Expand Down

0 comments on commit 49af006

Please sign in to comment.