Skip to content

Commit

Permalink
chore(#427): update language switcher block
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Jun 1, 2022
1 parent d2c8a08 commit d8ecc78
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions components/druxt/block/LanguageBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<b-dropdown-item
v-for="language of languages.filter((o) => o.attributes.drupal_internal__id !== 'und')"
:key="language.attributes.drupal_internal__id"
:to="`/${language.attributes.drupal_internal__id}`"
@click="changeLanguage(language.attributes.drupal_internal__id)"
>
<CountryFlag
class="align-bottom"
Expand Down Expand Up @@ -52,12 +52,36 @@ export default {
selected: ({ $route, languages }) => ($route.meta || {}).langcode
? languages.find((o) => o.attributes.drupal_internal__id === $route.meta.langcode)
: (languages.find((o) => o.attributes.drupal_internal__id === ((languages.find((o) => o.attributes.drupal_internal__id === 'und') || {}).attributes || {}).langcode) || {}),
route: ({ $store }) => $store.state.druxtRouter.route
},
methods: {
country: (iso) => (Object.entries({
async changeLanguage(langcode) {
switch (this.route.type) {
case 'entity': {
const { data } = await this.$store.dispatch('druxt/getResource', {
type: this.route.props.type,
id: this.route.props.uuid,
prefix: langcode,
query: new DrupalJsonApiParams().addFields(this.route.props.type, ['path'])
})
this.$router.push({ path: `/${langcode}${data.attributes.path.alias}` })
}
break
// Redirect to the correctly prefixed path.
default: {
const parts = this.route.resolvedPath.split('/')
parts[1] = langcode
this.$router.push({ path: parts.join('/') })
}
}
},
country: (langcode) => (Object.entries({
en: 'gb'
}).filter(([k, v]) => k === iso)).map(([k, v]) => v).pop() || iso
}).filter(([k, v]) => k === langcode)).map(([k, v]) => v).pop() || langcode
}
}
</script>

0 comments on commit d8ecc78

Please sign in to comment.