Skip to content

Commit

Permalink
Merge branch '208-feature-implement-page-title-translation-and-vike-l…
Browse files Browse the repository at this point in the history
…anguage' into 208-feat-page-title-translate
  • Loading branch information
Elweyn committed Mar 26, 2024
2 parents c12d5a7 + 82c9452 commit dac94d8
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion presenter/locales/extractLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function extractLocale(url: string) {
let urlWithoutLocale
// We remove the URL locale, for example `/de/about` => `/about`
const firstPath = urlPaths[1] as LocaleCode
if (locales.filter((locale) => locale !== localeDefault).includes(firstPath)) {
if (locales.includes(firstPath)) {
locale = firstPath
urlWithoutLocale = '/' + urlPaths.slice(2).join('/')
} else {
Expand Down
4 changes: 0 additions & 4 deletions presenter/renderer/+onBeforeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { PageContext } from 'vike/types'
import { extractLocale } from '#root/locales/extractLocale'

export function onBeforeRoute(pageContext: PageContext) {
if (pageContext.urlPathname.endsWith('.js')) {
return { pageContext: { urlLogical: pageContext.urlPathname } }
}

const { urlWithoutLocale, locale } = extractLocale(pageContext.urlPathname)

return {
Expand Down
2 changes: 1 addition & 1 deletion presenter/renderer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function createApp(pageContext: PageContext, isClient = true) {

setPageContext(app, pageContextReactive)

if (pageContext.locale !== undefined && locales.includes(pageContext.locale)) {
if (pageContext.locale && locales.includes(pageContext.locale)) {
i18n.global.locale.value = pageContext.locale
}

Expand Down
21 changes: 2 additions & 19 deletions presenter/src/components/language/LanguageSelector.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-select
v-model="selectedLocale"
v-model="$i18n.locale"
density="compact"
name="language"
:items="languages"
Expand All @@ -12,7 +12,6 @@
bg-color="transparent"
hide-details="auto"
flat
@update:model-value="updateLocale"
>
<template #selection="{ item }">
<span>{{ item.raw.locale.toUpperCase() }}</span>
Expand All @@ -30,25 +29,9 @@
<script lang="ts" setup>
import { ref } from 'vue'
import { usePageContext } from '#context/usePageContext'
import i18n from '#plugins/i18n'
import { locales, localizedLocale } from '#root/locales'
import { localizedLocale } from '#root/locales'
const languages = ref(localizedLocale)
const pageContext = usePageContext()
if (pageContext.locale !== undefined && locales.includes(pageContext.locale)) {
i18n.global.locale.value = pageContext.locale
}
const selectedLocale = ref(i18n.global.locale.value)
function updateLocale() {
if (locales.includes(selectedLocale.value)) {
i18n.global.locale.value = selectedLocale.value
}
}
</script>

<style lang="scss">
Expand Down

0 comments on commit dac94d8

Please sign in to comment.