feat: return full translation key

This commit is contained in:
kolaente 2021-12-30 17:14:43 +01:00 committed by Gitea
parent de77393905
commit 27534a98e9
3 changed files with 13 additions and 11 deletions

View file

@ -11,23 +11,23 @@ const dateWithHour = (hours: number): Date => {
describe('Salutation', () => { describe('Salutation', () => {
it('shows the right salutation in the night', () => { it('shows the right salutation in the night', () => {
const salutation = hourToSalutation(dateWithHour(4)) const salutation = hourToSalutation(dateWithHour(4))
expect(salutation).toBe('Night') expect(salutation).toBe('home.welcomeNight')
}) })
it('shows the right salutation in the morning', () => { it('shows the right salutation in the morning', () => {
const salutation = hourToSalutation(dateWithHour(8)) const salutation = hourToSalutation(dateWithHour(8))
expect(salutation).toBe('Morning') expect(salutation).toBe('home.welcomeMorning')
}) })
it('shows the right salutation in the day', () => { it('shows the right salutation in the day', () => {
const salutation = hourToSalutation(dateWithHour(13)) const salutation = hourToSalutation(dateWithHour(13))
expect(salutation).toBe('Day') expect(salutation).toBe('home.welcomeDay')
}) })
it('shows the right salutation in the night', () => { it('shows the right salutation in the night', () => {
const salutation = hourToSalutation(dateWithHour(20)) const salutation = hourToSalutation(dateWithHour(20))
expect(salutation).toBe('Evening') expect(salutation).toBe('home.welcomeEvening')
}) })
it('shows the right salutation in the night again', () => { it('shows the right salutation in the night again', () => {
const salutation = hourToSalutation(dateWithHour(23)) const salutation = hourToSalutation(dateWithHour(23))
expect(salutation).toBe('Night') expect(salutation).toBe('home.welcomeNight')
}) })
}) })

View file

@ -1,21 +1,23 @@
const TRANSLATION_KEY_PREFIX = 'home.welcome'
export function hourToSalutation(now: Date = new Date()): String { export function hourToSalutation(now: Date = new Date()): String {
const hours = new Date(now).getHours() const hours = new Date(now).getHours()
if (hours < 5) { if (hours < 5) {
return 'Night' return `${TRANSLATION_KEY_PREFIX}Night`
} }
if (hours < 11) { if (hours < 11) {
return 'Morning' return `${TRANSLATION_KEY_PREFIX}Morning`
} }
if (hours < 18) { if (hours < 18) {
return 'Day' return `${TRANSLATION_KEY_PREFIX}Day`
} }
if (hours < 23) { if (hours < 23) {
return 'Evening' return `${TRANSLATION_KEY_PREFIX}Evening`
} }
return 'Night' return `${TRANSLATION_KEY_PREFIX}Night`
} }

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="content has-text-centered"> <div class="content has-text-centered">
<h2 v-if="userInfo"> <h2 v-if="userInfo">
{{ $t(`home.welcome${welcome}`, {username: userInfo.name !== '' ? userInfo.name : userInfo.username}) }}! {{ $t(welcome, {username: userInfo.name !== '' ? userInfo.name : userInfo.username}) }}!
</h2> </h2>
<message variant="danger" v-if="deletionScheduledAt !== null" class="mb-4"> <message variant="danger" v-if="deletionScheduledAt !== null" class="mb-4">
{{ {{