Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(presenter): translate page title with i18n #397

Merged
merged 14 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion presenter/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ PUBLIC_ENV__ENDPOINTS__GRAPHQL_URI=http://localhost:4000/
PUBLIC_ENV__META__BASE_URL="http://localhost:3000"
PUBLIC_ENV__META__DEFAULT_AUTHOR="DreamMall Verlag GbR"
PUBLIC_ENV__META__DEFAULT_DESCRIPTION="Deine Reichweite Erweitern Alle Möglichkeiten Miteinander Ausschöpfen Lebensqualität Leben"
Elweyn marked this conversation as resolved.
Show resolved Hide resolved
PUBLIC_ENV__META__DEFAULT_TITLE="DreamMall"
3 changes: 2 additions & 1 deletion presenter/renderer/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { PageContext } from 'vike/types'

import i18n from '#plugins/i18n'
import { META } from '#src/env'

function getTitle(pageContext: PageContext) {
// The value exported by /pages/**/+title.js is available at pageContext.config.title
const val = pageContext.config.title
if (typeof val === 'string') return val
if (typeof val === 'function') return String(val(pageContext))
return META.DEFAULT_TITLE
return i18n.global.t('title')
Elweyn marked this conversation as resolved.
Show resolved Hide resolved
}
function getDescription(pageContext: PageContext) {
const val = pageContext.config.description
Expand Down
1 change: 0 additions & 1 deletion presenter/src/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('env', () => {
DEFAULT_AUTHOR: 'DreamMall Verlag GbR',
DEFAULT_DESCRIPTION:
'Deine Reichweite Erweitern Alle Möglichkeiten Miteinander Ausschöpfen Lebensqualität Leben',
DEFAULT_TITLE: 'DreamMall',
})
})
})
1 change: 0 additions & 1 deletion presenter/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const META = {
'DreamMall Verlag GbR') as string,
DEFAULT_DESCRIPTION: (import.meta.env.PUBLIC_ENV__META__DEFAULT_DESCRIPTION ??
'Deine Reichweite Erweitern Alle Möglichkeiten Miteinander Ausschöpfen Lebensqualität Leben') as string,
DEFAULT_TITLE: (import.meta.env.PUBLIC_ENV__META__DEFAULT_TITLE ?? 'DreamMall') as string,
}

export { AUTH, ENDPOINTS, META }
16 changes: 11 additions & 5 deletions presenter/src/locales/de.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"about": {},
"auth": {
"content": "Logge ein..."
"content": "Logge ein...",
"title": "DreamMall {'|'} Authentifizierung"
},
"dataProtection": {
"euDispute": {
Expand All @@ -26,7 +27,8 @@
"revocation": {
"content": "Nur mit Ihrer ausdrücklichen Einwilligung sind einige Vorgänge der Datenverarbeitung möglich. Ein Widerruf Ihrer bereits erteilten Einwilligung ist jederzeit möglich. Für den Widerruf genügt eine formlose Mitteilung per E-Mail. Die Rechtmäßigkeit der bis zum Widerruf erfolgten Datenverarbeitung bleibt vom Widerruf unberührt.",
"headline": "Widerruf Ihrer Einwilligung zur Datenverarbeitung"
}
},
"title": "DreamMall {'|'} Datenschutz"
},
"error": {
"404": {
Expand All @@ -36,7 +38,8 @@
"500": {
"h1": "500 Interner Fehler",
"text": "Etwas ist schief gegangen."
}
},
"title": "DreamMall {'|'} Fehler"
},
"home": {
"aboutSection": {
Expand Down Expand Up @@ -161,7 +164,8 @@
"content": "Umsatzsteuer-Identifikationsnummer gemäß § 27 a Umsatzsteuergesetz:",
"headline": "Umsatzsteuer-ID",
"id": "DE356946303"
}
},
"title": "DreamMall {'|'} Impressum"
},
"menu": {
"eMail": "E-Mail",
Expand Down Expand Up @@ -209,8 +213,10 @@
},
"success": {
"text": "Sie haben Ihr Newsletterabbonoment erfolgreich bestätigt. Sie werden in Kürze auf die Startseite weitergeleitet."
}
},
"title": "DreamMall {'|'} Newsletter"
},
"title": "DreamMall",
"validation": {
"fieldNoEmail": "Dieses Feld muss eine Email-Adresse sein.",
"fieldRequired": "Dieses Feld wird benötigt.",
Expand Down
16 changes: 11 additions & 5 deletions presenter/src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"about": {},
"auth": {
"content": "Logging in..."
"content": "Logging in...",
"title": "DreamMall {'|'} Authentication"
},
"dataProtection": {
"euDispute": {
Expand All @@ -26,7 +27,8 @@
"revocation": {
"content": "Some data processing operations are only possible with your express consent. You can withdraw your consent at any time. An informal notification by e-mail is sufficient for the revocation. The legality of the data processing carried out until the revocation remains unaffected by the revocation.",
"headline": "Withdrawal of your consent to data processing"
}
},
"title": "DreamMall {'|'} Privacy Policy"
},
"error": {
"404": {
Expand All @@ -36,7 +38,8 @@
"500": {
"h1": "500 Internal error",
"text": "Something went wrong."
}
},
"title": "DreamMall {'|'} Error"
},
"home": {
"aboutSection": {
Expand Down Expand Up @@ -161,7 +164,8 @@
"content": "Sales tax identification number according to § 27 a sales tax law:",
"headline": "Sales tax ID",
"id": "DE356946303"
}
},
"title": "DreamMall {'|'} Imprint"
},
"menu": {
"eMail": "E-Mail",
Expand Down Expand Up @@ -209,8 +213,10 @@
},
"success": {
"text": "You have successfully confirmed your newsletter subscription. You will be redirected to the start page shortly."
}
},
"title": "DreamMall {'|'} Newsletter"
},
"title": "DreamMall",
"validation": {
"fieldNoEmail": "This field must be an email address",
"fieldRequired": "This field is required",
Expand Down
6 changes: 5 additions & 1 deletion presenter/src/pages/_error/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const title = 'DreamMall | Fehler'
import i18n from '#plugins/i18n'

export const title = () => {
return i18n.global.t('error.title')
}
4 changes: 3 additions & 1 deletion presenter/src/pages/_error/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { describe, it, expect, beforeEach } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'

import ErrorPage from './+Page.vue'
import { title } from './+title'

describe('ErrorPage', () => {
it('title returns correct title', () => {
expect(title).toBe('DreamMall | Fehler')
expect(title()).toBe(i18n.global.t('error.title'))
})
describe('500 Error', () => {
const WrapperUndefined = () => {
Expand Down
6 changes: 5 additions & 1 deletion presenter/src/pages/auth/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const title = 'DreamMall | Authentifizierung'
import i18n from '#plugins/i18n'

export const title = () => {
return i18n.global.t('auth.title') // 'DreamMall | Authentifizierung'
}
3 changes: 2 additions & 1 deletion presenter/src/pages/auth/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'
import { useAuthStore } from '#stores/authStore'
import { authService } from '#tests/mock.authService'

Expand Down Expand Up @@ -51,7 +52,7 @@ describe('AuthPage', () => {
})

it('title returns correct title', () => {
expect(title).toBe('DreamMall | Authentifizierung')
expect(title()).toBe(i18n.global.t('auth.title'))
})

it('renders', () => {
Expand Down
6 changes: 5 additions & 1 deletion presenter/src/pages/datenschutz/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const title = 'DreamMall | Datenschutz'
import i18n from '#plugins/i18n'

export const title = () => {
return i18n.global.t('dataProtection.title')
}
4 changes: 3 additions & 1 deletion presenter/src/pages/datenschutz/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, it, expect } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'

import DataPrivacyPage from './+Page.vue'
import { title } from './+title'

Expand All @@ -14,7 +16,7 @@ describe('DataPrivacyPage', () => {
})

it('title returns correct title', () => {
expect(title).toBe('DreamMall | Datenschutz')
expect(title()).toBe(i18n.global.t('dataProtection.title'))
})

it('renders', () => {
Expand Down
7 changes: 6 additions & 1 deletion presenter/src/pages/impressum/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const title = 'DreamMall | Impressum'
import i18n from '#plugins/i18n'

// DreamMall | Impressum
export const title = () => {
return i18n.global.t('impress.title')
}
4 changes: 3 additions & 1 deletion presenter/src/pages/impressum/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, it, expect } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'

import ImpressumPage from './+Page.vue'
import { title } from './+title'

Expand All @@ -14,7 +16,7 @@ describe('ImpressumPage', () => {
})

it('title returns correct title', () => {
expect(title).toBe('DreamMall | Impressum')
expect(title()).toBe(i18n.global.t('impress.title'))
})

it('renders', () => {
Expand Down
6 changes: 4 additions & 2 deletions presenter/src/pages/index/+title.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { META } from '#src/env'
import i18n from '#plugins/i18n'

export const title = META.DEFAULT_TITLE
export const title = () => {
return i18n.global.t('title')
}
4 changes: 3 additions & 1 deletion presenter/src/pages/index/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { describe, it, expect } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'

import IndexPage from './+Page.vue'
import { title } from './+title'

Expand All @@ -14,7 +16,7 @@ describe('IndexPage', () => {
})

it('title returns default title', () => {
expect(title).toBe('DreamMall')
expect(title()).toBe(i18n.global.t('title'))
})

it('renders', () => {
Expand Down
7 changes: 6 additions & 1 deletion presenter/src/pages/optin/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const title = 'DreamMall | Newsletter'
import i18n from '#plugins/i18n'

// 'DreamMall | Newsletter'
export const title = () => {
return i18n.global.t('optin.title')
}
3 changes: 2 additions & 1 deletion presenter/src/pages/optin/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import { confirmNewsletter } from '#mutations/confirmNewsletter'
import i18n from '#plugins/i18n'
import { mockClient } from '#tests/mock.apolloClient'

import OptinPage from './+Page.vue'
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('OptinPage', () => {
})

it('title returns correct title', () => {
expect(title).toBe('DreamMall | Newsletter')
expect(title()).toBe(i18n.global.t('optin.title'))
})

it('route returns `/optin/@code', () => {
Expand Down
6 changes: 5 additions & 1 deletion presenter/src/pages/silent-refresh/+title.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export const title = 'DreamMall | Authentifizierung'
import i18n from '#plugins/i18n'

export const title = () => {
return i18n.global.t('auth.title') // 'DreamMall | Authentifizierung'
}
3 changes: 2 additions & 1 deletion presenter/src/pages/silent-refresh/Page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
import { Component, h } from 'vue'
import { VApp } from 'vuetify/components'

import i18n from '#plugins/i18n'
import { authService } from '#tests/mock.authService'

import SilentRefreshPage from './+Page.vue'
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('SilentRefreshPage', () => {
})

it('title returns correct title', () => {
expect(title).toBe('DreamMall | Authentifizierung')
expect(title()).toBe(i18n.global.t('auth.title'))
})

it('renders', () => {
Expand Down
Loading