Skip to content

Commit

Permalink
Add option to generate links to home of locale
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Sep 20, 2022
1 parent a21e220 commit 9998df2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion components/locale-selector/locale-selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')

</template>

Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions components/locale-selector/locale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

</template>
Expand All @@ -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: -> []
Expand All @@ -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

</script>

Expand Down

0 comments on commit 9998df2

Please sign in to comment.