Skip to content

Commit

Permalink
feat: add Russian translation, fix translations
Browse files Browse the repository at this point in the history
  • Loading branch information
evermake committed Apr 7, 2024
1 parent 1684302 commit 07d7548
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 45 deletions.
24 changes: 1 addition & 23 deletions backend/src/bot/handlers/views/semesters_summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,9 @@ const BackButton = makeButton({ id: `${VIEW_ID}:back` })
export default {
render: async (ctx) => {
const semesters = await ctx.domain.getSemestersSummary({ telegramId: ctx.from!.id })

return (
<>
<b>Semesters history</b>
<br />
<br />
{semesters.map(({ title, hoursTotal, fitnessTest }) => (
<>
{ctx.t.BeautifulSemesterTitle(title)}
<br />
{(hoursTotal != null) && (
<>
{`• ${hoursTotal} hours`}
<br />
</>
)}
{fitnessTest && (
<>
{`• Fitness test: ${fitnessTest.pointsTotal} points (${fitnessTest.passed ? 'passed' : 'not passed'})`}
<br />
</>
)}
<br />
</>
))}
{ctx.t['Views.SemestersSummary.SummaryMessage'](semesters)}
<keyboard>
<BackButton>{ctx.t['Buttons.Back']}</BackButton>
</keyboard>
Expand Down
4 changes: 2 additions & 2 deletions backend/src/bot/handlers/views/trainings_training.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
trainingId: ctx.payload.trainingId,
})
ctx.answerCallbackQuery({
text: 'Checked-in',
text: ctx.t['Alert.CheckInSuccessfulText'],
show_alert: true,
})

Expand All @@ -95,7 +95,7 @@ export default {
trainingId: ctx.payload.trainingId,
})
ctx.answerCallbackQuery({
text: 'Cancelled check-in',
text: ctx.t['Alert.CheckInCancelledText'],
show_alert: true,
})

Expand Down
63 changes: 47 additions & 16 deletions backend/src/translations/_en.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { pluralize } from './utils'
import { TIMEZONE } from '~/constants'
import type { SemesterSummary } from '~/domain/types'
import type { TrainingDetailed } from '~/services/sport/types'
import type { Weekday } from '~/utils/dates'
import { clockTime } from '~/utils/dates'
Expand All @@ -24,6 +26,19 @@ function dateAndTimeShort(
return `${weekDayShort} ${monthShort} ${dayOfMonth}, ${clockTime(startsAt, TIMEZONE)}${clockTime(endsAt, TIMEZONE)}`
}

function beautifulSemesterTitle(raw: string): string {
const match = raw.toLowerCase().match(/^([sf]|sum)(\d{2})$/i)
if (!match) {
return raw
}

const [, season, year] = match
const seasonName = season === 's' ? 'Spring' : season === 'f' ? 'Fall' : 'Summer'
const emoji = season === 's' ? '🌷' : season === 'f' ? '🍂' : '☀️'
const formattedYear = `20${year}`
return `${seasonName} ${formattedYear} ${emoji}`
}

const INSPIRING_QUOTES = [
'The only bad workout is the one that didn\'t happen.',
'The only way to finish is to start.',
Expand Down Expand Up @@ -72,12 +87,14 @@ export default {
'HowGoodAmI.Answer': (percent: number) => `You're better than ${percent}% of students!`,
'HowGoodAmI.Failed': 'I don\'t know 🤷‍♂️',

'Alert.CheckInSuccessfulText': 'Check-in successful.',
'Alert.CheckInSuccessful': ({ title, startsAt, endsAt }: TrainingDetailed) => [
'Check-in successful.',
'',
title,
dateAndTimeShort(startsAt, endsAt),
].join('\n'),
'Alert.CheckInCancelledText': 'Check-in cancelled.',
'Alert.CheckInCancelled': ({ title, startsAt, endsAt }: TrainingDetailed) => [
'Check-in cancelled.',
'',
Expand All @@ -104,15 +121,15 @@ export default {
<>
<b>Your progress:</b>
<br />
{`🎉 ${earned} hours out of ${required}${debt ? `+${debt} (debt)` : ''} 🎉`}
{`🎉 ${earned} ${pluralize(earned, 'hour', 'hours', 'hours')} out of ${required}${debt ? `+${debt} (debt)` : ''} 🎉`}
</>
)
} else {
return (
<>
<b>Your progress:</b>
<br />
{`${earned} hours out of ${required}${debt ? `+${debt} (debt)` : ''}`}
{`${earned} ${pluralize(earned, 'hour', 'hours', 'hours')} out of ${required}${debt ? `+${debt} (debt)` : ''}`}
<br />
<blockquote>{INSPIRING_QUOTES[Math.floor(Math.random() * INSPIRING_QUOTES.length)]}</blockquote>
</>
Expand Down Expand Up @@ -172,7 +189,34 @@ export default {
'Views.Training.Buttons.CheckIn': 'Check-in',
'Views.Training.Buttons.CancelCheckIn': 'Cancel check-in',

'Weekday.TwoLetters': (weekday: Weekday) => {
'Views.SemestersSummary.SummaryMessage': (semesters: SemesterSummary[]) => (
<>
<b>Semesters history</b>
<br />
<br />
{semesters.map(({ title, hoursTotal, fitnessTest }) => (
<>
{beautifulSemesterTitle(title)}
<br />
{(hoursTotal != null) && (
<>
{`• ${hoursTotal} ${pluralize(hoursTotal, 'hour', 'hours', 'hours')}`}
<br />
</>
)}
{fitnessTest && (
<>
{`• Fitness test: ${fitnessTest.pointsTotal} ${pluralize(fitnessTest.pointsTotal, 'point', 'points', 'points')} (${fitnessTest.passed ? 'passed' : 'not passed'})`}
<br />
</>
)}
<br />
</>
))}
</>
),

'Weekday.TwoLetters': (weekday: Weekday): string => {
switch (weekday) {
case 'mon': return 'Mo'
case 'tue': return 'Tu'
Expand All @@ -183,17 +227,4 @@ export default {
case 'sun': return 'Su'
}
},

'BeautifulSemesterTitle': (raw: string) => {
const match = raw.toLowerCase().match(/^([sf]|sum)(\d{2})$/i)
if (!match) {
return raw
}

const [, season, year] = match
const seasonName = season === 's' ? 'Spring' : season === 'f' ? 'Fall' : 'Summer'
const emoji = season === 's' ? '🌷' : season === 'f' ? '🍂' : '☀️'
const formattedYear = `20${year}`
return `${seasonName} ${formattedYear} ${emoji}`
},
}
4 changes: 0 additions & 4 deletions backend/src/translations/_ru.ts

This file was deleted.

Loading

0 comments on commit 07d7548

Please sign in to comment.