Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Translate module-level labels at render time (#1416)

Dave Earley439a48b68355
diff --git a/e2e/tests/ssr/server-translations.spec.ts b/e2e/tests/ssr/server-translations.spec.ts
new file mode 100644
index 000000000..efe0bf8a9
--- /dev/null
+++ b/e2e/tests/ssr/server-translations.spec.ts
@@ -0,0 +1,30 @@
+import {expect, test} from '../../fixtures';
+
+test.describe('@smoke server-rendered translations', () => {
+ test('each request is translated in its own locale on the server', async ({request}) => {
+ for (const [language, feature] of [['de', 'Wiederkehrende Veranstaltungen'], ['en', 'Recurring events']]) {
+ const html = await (await request.get('/auth/login', {headers: {'Accept-Language': language}})).text();
+ expect(html).toContain(feature);
+ }
+ });
+
+ for (const path of ['/auth/login', '/auth/register']) {
+ test(`${path} hydrates without errors`, async ({page}) => {
+ const errors: string[] = [];
+ page.on('pageerror', error => errors.push(error.message));
+ page.on('console', message => {
+ if (message.type() === 'error') {
+ errors.push(message.text());
+ }
+ });
+
+ await page.goto(path);
+ const feature = page.getByText('Recurring events').first();
+ await expect(feature).toBeVisible();
+ await expect.poll(() => feature.evaluate(node => Object.keys(node).some(key => key.startsWith('__reactFiber$')))).toBe(true);
+ await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => setTimeout(resolve))));
+
+ expect(errors.filter(error => /hydrat|#418|#423|#425/i.test(error))).toEqual([]);
+ });
+ }
+});
diff --git a/frontend/src/components/common/OrganizerReportTable/index.tsx b/frontend/src/components/common/OrganizerReportTable/index.tsx
index e10db9c61..870fc11ca 100644
--- a/frontend/src/components/common/OrganizerReportTable/index.tsx
+++ b/frontend/src/components/common/OrganizerReportTable/index.tsx
@@ -48,7 +48,7 @@ interface OrganizerReportProps<T> {
eventId?: number | null;
}
-const TIME_PERIODS = [
+const getTimePeriods = () => [
{value: '24h', label: t`Last 24 hours`},
{value: '48h', label: t`Last 48 hours`},
{value: '7d', label: t`Last 7 days`},
@@ -315,7 +315,7 @@ const OrganizerReportTable = <T extends Record<string, any>>({
<Select
style={{minWidth: '200px'}}
placeholder={t`Select time period`}
- data={TIME_PERIODS}
+ data={getTimePeriods()}
value={selectedPeriod}
onChange={handlePeriodChange}
leftSection={<IconCalendar stroke={1.5} size={20}/>}
diff --git a/frontend/src/components/common/ReportTable/index.tsx b/frontend/src/components/common/ReportTable/index.tsx
index d29d1bda7..af4603df5 100644
--- a/frontend/src/components/common/ReportTable/index.tsx
+++ b/frontend/src/components/common/ReportTable/index.tsx
@@ -43,7 +43,7 @@ interface ReportProps<T> {
showCustomDatePicker?: boolean;
}
-const TIME_PERIODS = [
+const getTimePeriods = () => [
{value: '24h', label: t`Last 24 hours`},
{value: '48h', label: t`Last 48 hours`},
{value: '7d', label: t`Last 7 days`},
@@ -278,7 +278,7 @@ const ReportTable = <T extends Record<string, any>>({
<Select
style={{minWidth: '200px'}}
placeholder={t`Select time period`}
- data={TIME_PERIODS}
+ data={getTimePeriods()}
value={selectedPeriod}
onChange={handlePeriodChange}
leftSection={<IconCalendar stroke={1.5} size={20}/>}
diff --git a/frontend/src/components/layouts/AuthLayout/AuthShell.tsx b/frontend/src/components/layouts/AuthLayout/AuthShell.tsx
index 4a57b0713..15635d659 100644
--- a/frontend/src/components/layouts/AuthLayout/AuthShell.tsx
+++ b/frontend/src/components/layouts/AuthLayout/AuthShell.tsx
@@ -8,7 +8,7 @@ import {getConfig} from "../../../utilites/config.ts";
import {isHiEvents} from "../../../utilites/helpers.ts";
import {showInfo} from "../../../utilites/notifications.tsx";
-const tickerFeatures = [
+const getTickerFeatures = () => [
t`Recurring events`,
t`Instant Stripe payouts`,
t`Custom branding`,
@@ -28,6 +28,7 @@ const tickerFeatures = [
];
const FeaturePanel = () => {
+ const tickerFeatures = getTickerFeatures();
const tickerLoop = [...tickerFeatures, ...tickerFeatures];
return (
diff --git a/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx b/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx
index 6b01b415c..e1e8449fc 100644
--- a/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx
+++ b/frontend/src/components/routes/event/OccurrencesTab/RecurrenceScheduleDrawer/index.tsx
@@ -41,7 +41,7 @@ import {DateField} from "../../../../common/DateField";
const MAX_PREVIEW = 1200;
-const DAYS_OF_WEEK = [
+const getDaysOfWeek = () => [
{value: 'sunday', label: t`Sun`, full: t`Sunday`},
{value: 'monday', label: t`Mon`, full: t`Monday`},
{value: 'tuesday', label: t`Tue`, full: t`Tuesday`},
@@ -53,20 +53,20 @@ const DAYS_OF_WEEK = [
const useDaysOfWeekInDisplayOrder = () => {
const {firstDayOfWeek} = useDatesContext();
- return useMemo(
- () => Array.from({length: 7}, (_, i) => DAYS_OF_WEEK[(firstDayOfWeek + i) % 7]),
- [firstDayOfWeek]
- );
+ return useMemo(() => {
+ const daysOfWeek = getDaysOfWeek();
+ return Array.from({length: 7}, (_, i) => daysOfWeek[(firstDayOfWeek + i) % 7]);
+ }, [firstDayOfWeek]);
};
-const FREQUENCIES = [
+const getFrequencies = () => [
{value: 'daily', label: t`Daily`},
{value: 'weekly', label: t`Weekly`},
{value: 'monthly', label: t`Monthly`},
{value: 'yearly', label: t`Yearly`},
];
-const WEEK_POSITIONS = [
+const getWeekPositions = () => [
{value: '1', label: t`First`},
{value: '2', label: t`Second`},
{value: '3', label: t`Third`},
@@ -74,7 +74,7 @@ const WEEK_POSITIONS = [
{value: '-1', label: t`Last`},
];
-const MONTHS = [
+const getMonths = () => [
{value: '1', label: t`January`},
{value: '2', label: t`February`},
{value: '3', label: t`March`},
@@ -787,12 +787,12 @@ export const RecurrenceScheduleDrawer = ({onClose, onGenerationStarted}: Recurre
.join(', ');
if (dayList) onPart = t`on ${dayList}`;
} else {
- const position = WEEK_POSITIONS.find(p => p.value === values.week_position)?.label ?? '';
- const day = DAYS_OF_WEEK.find(d => d.value === values.day_of_week)?.full ?? '';
+ const position = getWeekPositions().find(p => p.value === values.week_position)?.label ?? '';
+ const day = getDaysOfWeek().find(d => d.value === values.day_of_week)?.full ?? '';
onPart = t`on the ${position} ${day}`;
}
} else if (values.frequency === 'yearly') {
- const month = MONTHS.find(m => m.value === values.yearly_month)?.label ?? '';
+ const month = getMonths().find(m => m.value === values.yearly_month)?.label ?? '';
const day = values.yearly_day;
onPart = t`on ${month} ${day}`;
}
@@ -907,7 +907,7 @@ export const RecurrenceScheduleDrawer = ({onClose, onGenerationStarted}: Recurre
size="xs"
value={form.values.frequency}
onChange={(value) => form.setFieldValue('frequency', value)}
- data={FREQUENCIES}
+ data={getFrequencies()}
/>
</div>
@@ -949,7 +949,7 @@ export const RecurrenceScheduleDrawer = ({onClose, onGenerationStarted}: Recurre
<span className={classes.sentenceWord}>{t`on`}</span>
<Select
aria-label={t`Month`}
- data={MONTHS}
+ data={getMonths()}
className={classes.inlineSelect}
{...form.getInputProps('yearly_month')}
/>
@@ -985,7 +985,7 @@ export const RecurrenceScheduleDrawer = ({onClose, onGenerationStarted}: Recurre
<div className={classNames(classes.patternContent, classes.sentenceRow)}>
<Select
aria-label={t`Position`}
- data={WEEK_POSITIONS}
+ data={getWeekPositions()}
className={classes.inlineSelect}
{...form.getInputProps('week_position')}
/>
diff --git a/frontend/src/components/routes/event/attendees.tsx b/frontend/src/components/routes/event/attendees.tsx
index 20c37a4b7..41c4dcefd 100644
--- a/frontend/src/components/routes/event/attendees.tsx
+++ b/frontend/src/components/routes/event/attendees.tsx
@@ -26,7 +26,7 @@ import {useGetEventOccurrences} from "../../../queries/useGetEventOccurrences.ts
import {SortSelector} from "../../common/SortSelector";
import {OccurrenceSelect} from "../../common/OccurrenceSelect";
-const attendeeStatuses = [
+const getAttendeeStatuses = () => [
{label: t`Active`, value: 'ACTIVE'},
{label: t`Cancelled`, value: 'CANCELLED'},
{label: t`Awaiting Payment`, value: 'AWAITING_PAYMENT'},
@@ -81,7 +81,7 @@ const Attendees = () => {
field: 'status',
label: t`Attendee Status`,
type: 'multi-select',
- options: attendeeStatuses
+ options: getAttendeeStatuses()
}
];
diff --git a/frontend/src/components/routes/event/orders.tsx b/frontend/src/components/routes/event/orders.tsx
index 370e4f5c6..0d3a99785 100644
--- a/frontend/src/components/routes/event/orders.tsx
+++ b/frontend/src/components/routes/event/orders.tsx
@@ -27,13 +27,13 @@ import {useLicensedFeature} from "../../../ee/licensing/hooks/useLicensedFeature
import {FeatureFlag} from "../../../constants/featureFlags.ts";
import {getProductsFromEvent} from "../../../utilites/helpers.ts";
-const orderStatuses = [
+const getOrderStatuses = () => [
{label: t`Completed`, value: 'COMPLETED'},
{label: t`Cancelled`, value: 'CANCELLED'},
{label: t`Awaiting Offline Payment`, value: 'AWAITING_OFFLINE_PAYMENT'},
];
-const refundStatuses = [
+const getRefundStatuses = () => [
{label: t`Refunded`, value: 'REFUNDED'},
{label: t`Partially Refunded`, value: 'PARTIALLY_REFUNDED'},
];
@@ -73,13 +73,13 @@ export const Orders: React.FC = () => {
field: 'status',
label: t`Order Status`,
type: 'multi-select',
- options: orderStatuses
+ options: getOrderStatuses()
},
{
field: 'refund_status',
label: t`Refund Status`,
type: 'multi-select',
- options: refundStatuses
+ options: getRefundStatuses()
},
...(boxOffices.length > 0 ? [{
field: 'box_office_id',
diff --git a/frontend/src/components/routes/organizer/Settings/Sections/SocialLinks/index.tsx b/frontend/src/components/routes/organizer/Settings/Sections/SocialLinks/index.tsx
index 07ccc9a30..8a11208b7 100644
--- a/frontend/src/components/routes/organizer/Settings/Sections/SocialLinks/index.tsx
+++ b/frontend/src/components/routes/organizer/Settings/Sections/SocialLinks/index.tsx
@@ -41,7 +41,7 @@ interface SocialPlatform {
priority?: 'primary' | 'secondary';
}
-const socialPlatforms: SocialPlatform[] = [
+const getSocialPlatforms = (): SocialPlatform[] => [
{
name: t`Facebook`,
field: 'facebook_handle',
@@ -110,6 +110,7 @@ export const SocialLinks = () => {
const organizerSettingsQuery = useGetOrganizerSettings(organizerId);
const updateMutation = useUpdateOrganizerSettings();
const [showMore, setShowMore] = useState(false);
+ const socialPlatforms = getSocialPlatforms();
const initialValues = socialPlatforms.reduce((acc, platform) => {
acc[platform.field] = '';