diff --git a/components/locale-selector/locale-selector.vue b/components/locale-selector/locale-selector.vue index 08f3edb..a29e85a 100644 --- a/components/locale-selector/locale-selector.vue +++ b/components/locale-selector/locale-selector.vue @@ -20,7 +20,8 @@ cloak-i18n-locale-selector-dropdown.locale-selector //- A locale option cloak-i18n-locale( :locale='locales[0]' - :language-locales='locales') + :language-locales='locales' + :redirect-home='redirectHome') @@ -30,6 +31,9 @@ cloak-i18n-locale-selector-dropdown.locale-selector import groupBy from 'lodash/groupBy' export default + props: + redirectHome: Boolean # Make links to homepages rather than current page + computed: # Get the current locale object diff --git a/components/locale-selector/locale.vue b/components/locale-selector/locale.vue index d4071c8..2ff2cad 100644 --- a/components/locale-selector/locale.vue +++ b/components/locale-selector/locale.vue @@ -22,7 +22,7 @@ v-for='languageLocale in languageLocales' :key='languageLocale.languageCode' :aria-label='languageLocale.language' - :href='switchLocalePath(languageLocale.code)') + :href='makeUrl(languageLocale.code)') | {{ languageLocale.languageCode }} @@ -35,6 +35,7 @@ export default props: locale: Object # The locale object isLabel: Boolean # Disables links on country + redirectHome: Boolean # Make links to homepages rather than current page languageLocales: # List of alternative language options for the locale type: Array default: -> [] @@ -49,8 +50,17 @@ export default # The element to use on country links countryLink: -> if @isLabel then 'span' else 'a' - # The primary url for the locale - url: -> unless @isLabel then @switchLocalePath @locale.code + # Make the country level link + url: -> @makeUrl @locale.code unless @isLabel + + methods: + + # Make the URL to a locale code. These helper functions come + # from @nuxtjs/i18n + makeUrl: (code) -> + if @redirectHome + then @localePath '/', @locale.code + else @switchLocalePath @locale.code