fix(mobile): Arabic reads in its direction: arrows turn round, Latin names keep their ends, figures stay whole

In the touch shell the back, forward, disclosure, date-range and flow
arrows kept pointing right in Arabic, so Settle up showed the debt the
wrong way round and Vacay's year arrows pointed inward. The shell now
mirrors lucide's direction arrows in right-to-left languages; an icon
that names its own treatment keeps it, and the lightbox arrows stay on
their physical sides.

Latin user text in Arabic rows lost its beginning when cut and moved its
punctuation to the wrong end. Names, titles, addresses and file names take
their direction from their own text (dir=auto) and still line up with the
row; markdown paragraphs, chat messages, poll options and journal stories
are isolated; signed balances, amounts, sizes, rates and leg figures read
as one left-to-right run; URL fields read left to right. Name pairs joined
by an arrow isolate each name and point from the first to the second.

The hero progress and poll result bars fill from the start edge. Arabic
and Hebrew uppercase caption labels grow a step and take the muted ink,
and a todo's due date in a notification is written in the reader's
language instead of as YYYY-MM-DD.
This commit is contained in:
Maurice
2026-11-07 23:21:33 +01:00
parent 2a6c771ad9
commit bf00412863
61 changed files with 496 additions and 128 deletions
@@ -77,8 +77,9 @@ describe('JournalBody', () => {
const { container } = render(<JournalBody text={'# Big\n\n### Small'} />);
expect(container.querySelector('h1')).not.toBeInTheDocument();
expect(container.querySelector('h3')).not.toBeInTheDocument();
expect(screen.getByText('Big').tagName).toBe('P');
expect(screen.getByText('Small').tagName).toBe('P');
// Each paragraph's text sits in an isolate (<bdi>) so it keeps its own direction.
expect(screen.getByText('Big').parentElement?.tagName).toBe('P');
expect(screen.getByText('Small').parentElement?.tagName).toBe('P');
});
it('FE-COMP-JOURNALBODY-012: keeps a setext underline as text instead of a heading', () => {
@@ -15,13 +15,14 @@ export default function JournalBody({ text, dark }: Props) {
lineHeight: 1.6,
color: 'inherit',
}}>
{/* Each paragraph in its own direction (bdi): a Latin story in the Arabic UI keeps its full stop at its end. */}
<ReactMarkdown
remarkPlugins={[remarkGfm, remarkBreaks]}
components={{
h1: ({ children }) => <p style={{ margin: '0 0 6px' }}>{children}</p>,
h2: ({ children }) => <p style={{ margin: '0 0 6px' }}>{children}</p>,
h3: ({ children }) => <p style={{ margin: '0 0 6px' }}>{children}</p>,
p: ({ children }) => <p style={{ margin: '0 0 6px' }}>{children}</p>,
h1: ({ children }) => <p style={{ margin: '0 0 6px' }}><bdi>{children}</bdi></p>,
h2: ({ children }) => <p style={{ margin: '0 0 6px' }}><bdi>{children}</bdi></p>,
h3: ({ children }) => <p style={{ margin: '0 0 6px' }}><bdi>{children}</bdi></p>,
p: ({ children }) => <p style={{ margin: '0 0 6px' }}><bdi>{children}</bdi></p>,
blockquote: ({ children }) => (
<blockquote style={{
borderInlineStart: `3px solid var(--journal-accent)`,
@@ -3,7 +3,7 @@ import { Check, X, ArrowRight, Trash2, CheckCheck, Mail } from 'lucide-react'
import { useTranslation } from '../../i18n'
import type { InAppNotification } from '../../store/inAppNotificationStore'
import { compactTime, useNotificationItemActions } from './useNotificationItemActions'
import { KIND_LOOK, createdAt, kindOf } from './notificationModel'
import { KIND_LOOK, createdAt, kindOf, localizedParams } from './notificationModel'
interface NotificationItemProps {
notification: InAppNotification
@@ -55,7 +55,7 @@ export default function InAppNotificationItem({ notification, onClose }: Notific
useNotificationItemActions(notification, onClose)
const titleText = t(notification.title_key, notification.title_params)
const bodyText = t(notification.text_key, notification.text_params)
const bodyText = t(notification.text_key, localizedParams(notification.text_params, locale))
const unread = !notification.is_read
const answered = notification.response !== null
const { positive_text_key: yesKey, negative_text_key: noKey, navigate_text_key: goKey } = notification
@@ -1,5 +1,5 @@
/**
* FE-NOTIF-MODEL-001 to FE-NOTIF-MODEL-007
* FE-NOTIF-MODEL-001 to FE-NOTIF-MODEL-009
*
* What a notification's tile shows, how the server's time is read, and how the
* list is cut into days under headings in the reader's language.
@@ -9,7 +9,7 @@ import { describe, expect, it } from 'vitest';
import { render, screen } from '../../../tests/helpers/render';
import type { InAppNotification } from '../../store/inAppNotificationStore';
import NotificationDayList from './NotificationDayList';
import { KIND_LOOK, createdAt, dayLabel, groupByDay, kindOf } from './notificationModel';
import { KIND_LOOK, createdAt, dayLabel, groupByDay, kindOf, localizedParams } from './notificationModel';
const note = (id: number, created_at: string, title_key = 'notif.trip_invite.title'): InAppNotification => ({
id,
@@ -89,3 +89,21 @@ describe('NotificationDayList', () => {
expect(screen.getAllByRole('region')).toHaveLength(2);
});
});
describe('localizedParams', () => {
const NOW = new Date(2026, 10, 7, 12);
it('FE-NOTIF-MODEL-008: a due day sent as YYYY-MM-DD reads as the short date of the language', () => {
const params = { todo: 'Exchange the JR Pass', trip: 'Kyoto', due: '2026-11-05' };
expect(localizedParams(params, 'de', NOW)).toEqual({ todo: 'Exchange the JR Pass', trip: 'Kyoto', due: '5. Nov.' });
expect(localizedParams(params, 'en-US', NOW).due).toBe('Nov 5');
expect(localizedParams(params, 'ru', NOW).due).toBe('5 нояб.');
// Another year names it.
expect(localizedParams({ due: '2027-01-02' }, 'en-US', NOW).due).toBe('Jan 2, 2027');
});
it('FE-NOTIF-MODEL-009: anything that is not a bare date passes through, and no params stay none', () => {
expect(localizedParams({ trip: '2026-11-05 at noon', n: '3' }, 'de', NOW)).toEqual({ trip: '2026-11-05 at noon', n: '3' });
expect(localizedParams(undefined, 'de', NOW)).toEqual({});
});
});
@@ -80,6 +80,34 @@ export function createdAt(value: string): Date {
const dayStart = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
const BARE_DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
/**
* The parameters of a notification's text as the reader's language writes
* them. A day the server sends (a todo's due date) arrives as YYYY-MM-DD, which
* would stand as "2026-11-05" in a German or Arabic sentence; it becomes the
* short date of the language ("5. Nov.", "٥ نوفمبر"), with the year only when
* it is not this one. Everything else passes through as it came.
*/
export function localizedParams(
params: Record<string, string> | null | undefined,
locale: string,
now: Date = new Date()
): Record<string, string> {
const out: Record<string, string> = { ...params };
for (const [key, value] of Object.entries(out)) {
const day = BARE_DAY.exec(value);
if (!day) continue;
const date = new Date(Number(day[1]), Number(day[2]) - 1, Number(day[3]));
out[key] = new Intl.DateTimeFormat(locale, {
day: 'numeric',
month: 'short',
...(date.getFullYear() === now.getFullYear() ? {} : { year: 'numeric' }),
}).format(date);
}
return out;
}
/**
* The heading of the day a notification belongs to, in the reader's language:
* today and yesterday by name, the rest of the week by weekday, anything older
@@ -41,4 +41,23 @@ describe('MarkdownText', () => {
expect(wrapper.className).toContain('truncate')
expect(wrapper.className).toContain('text-m-muted')
})
it('FE-MDTEXT-007: a clamped row takes its direction from its own text, so a Latin address in Arabic is cut at its end', () => {
const { container } = render(<MarkdownText clamp>{'68 Fukakusa Yabunouchicho, Fushimi Ward, Kyoto'}</MarkdownText>)
const wrapper = container.firstElementChild as HTMLElement
expect(wrapper).toHaveAttribute('dir', 'auto')
expect(wrapper).toHaveClass('truncate')
// No isolate inside: dir="auto" would not see the text through a <bdi>.
expect(wrapper.querySelector('bdi')).toBeNull()
})
it('FE-MDTEXT-008: in a full view each paragraph runs in its own direction, inside its block', () => {
const text = ["Kyoto's kitchen: pickles and matcha everything.", 'Second paragraph?'].join('\n\n')
const { container } = render(<MarkdownText>{text}</MarkdownText>)
expect(container.firstElementChild).not.toHaveAttribute('dir')
const paragraphs = container.querySelectorAll('p')
expect(paragraphs).toHaveLength(2)
paragraphs.forEach(p => expect(p.firstElementChild?.tagName).toBe('BDI'))
expect(paragraphs[1].textContent).toBe('Second paragraph?')
})
})
@@ -3,6 +3,7 @@ import type { Components } from 'react-markdown'
import remarkGfm from 'remark-gfm'
import remarkBreaks from 'remark-breaks'
import { markdownLinkComponents } from './markdownLink'
import { isolatedTextBlocks } from './markdownSanitize'
/**
* A clamped caption lives inside a tappable row, so an anchor there would eat
@@ -12,6 +13,8 @@ const clampedComponents: Components = {
a: ({ children }) => <>{children}</>,
}
const fullComponents: Components = { ...isolatedTextBlocks, ...markdownLinkComponents }
/**
* A description or note, rendered (#2337). The field is Markdown wherever it is
* written — the editors ship a formatting bar — so printing it raw anywhere
@@ -20,6 +23,9 @@ const clampedComponents: Components = {
* `clamp` is the list-row variant: one line high, matching what the desktop
* sidebar rows do with the same field. The height cap is inline because the row
* itself sets a font size, and a Tailwind `leading-*` would race with it.
* The clamped line takes its direction from its own text (dir="auto" on the
* row, which a <bdi> inside would hide from it), so a Latin address in an Arabic
* row loses its end at the cut, not its beginning.
*/
export default function MarkdownText({ children, className = '', clamp = false }: {
children: string
@@ -28,12 +34,13 @@ export default function MarkdownText({ children, className = '', clamp = false }
}) {
return (
<div
dir={clamp ? 'auto' : undefined}
className={`collab-note-md ${clamp ? 'truncate ' : ''}${className}`}
style={clamp ? { maxHeight: '1.2em', lineHeight: 1.2 } : undefined}
>
<Markdown
remarkPlugins={[remarkGfm, remarkBreaks]}
components={clamp ? clampedComponents : markdownLinkComponents}
components={clamp ? clampedComponents : fullComponents}
>
{children}
</Markdown>
@@ -31,6 +31,35 @@ export const sanitizedMarkdownPlugins: NonNullable<Options['rehypePlugins']> = [
[rehypeSanitize, schema],
]
/**
* A paragraph or heading of user text runs in its own direction: a Latin note
* in the Arabic UI keeps its question mark and full stop at its end (and an
* Arabic one in an English UI), while the block keeps the alignment of the page
* around it. The isolate is inline, so the block itself stays as it was.
*/
export const isolatedTextBlocks: Components = {
p: ({ children }) => (
<p>
<bdi>{children}</bdi>
</p>
),
h1: ({ children }) => (
<h1>
<bdi>{children}</bdi>
</h1>
),
h2: ({ children }) => (
<h2>
<bdi>{children}</bdi>
</h2>
),
h3: ({ children }) => (
<h3>
<bdi>{children}</bdi>
</h3>
),
}
/**
* Links as in markdownLinkComponents (#1629): own tab plus `rel` protection.
* The exception is a footnote or heading link, which points inside the text
@@ -38,6 +67,7 @@ export const sanitizedMarkdownPlugins: NonNullable<Options['rehypePlugins']> = [
* somewhere else.
*/
export const sanitizedMarkdownComponents: Components = {
...isolatedTextBlocks,
a: ({ children, href, ...rest }) =>
href?.startsWith('#') ? (
<a {...rest} href={href}>