Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(app): set text direction from locale and add bidi isolates

Hampusa66033bfa315
diff --git a/fluxer_app/src/features/i18n/components/AppI18nProvider.tsx b/fluxer_app/src/features/i18n/components/AppI18nProvider.tsx
index 8d75b8f56..8944deeb5 100644
--- a/fluxer_app/src/features/i18n/components/AppI18nProvider.tsx
+++ b/fluxer_app/src/features/i18n/components/AppI18nProvider.tsx
@@ -1,14 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {TranslationSafeMessage} from '@app/features/i18n/components/TranslationSafeMessage';
+import {getLocaleDirection} from '@app/features/i18n/utils/LocaleDirection';
+import {DirectionProvider} from '@base-ui/react/direction-provider';
import type {I18n} from '@lingui/core';
-import {I18nProvider} from '@lingui/react';
+import {I18nProvider, useLingui} from '@lingui/react';
import type {ReactNode} from 'react';
+function LocaleDirectionProvider({children}: {children?: ReactNode}): ReactNode {
+ const {i18n} = useLingui();
+ return (
+ <DirectionProvider
+ direction={getLocaleDirection(i18n.locale)}
+ data-flx="i18n.app-i18n-provider.locale-direction-provider.direction-provider"
+ >
+ {children}
+ </DirectionProvider>
+ );
+}
+
export function AppI18nProvider({i18n, children}: {i18n: I18n; children?: ReactNode}): ReactNode {
return (
<I18nProvider i18n={i18n} defaultComponent={TranslationSafeMessage}>
- {children}
+ <LocaleDirectionProvider data-flx="i18n.app-i18n-provider.locale-direction-provider">
+ {children}
+ </LocaleDirectionProvider>
</I18nProvider>
);
}
diff --git a/fluxer_app/src/features/i18n/utils/BidiIsolate.ts b/fluxer_app/src/features/i18n/utils/BidiIsolate.ts
new file mode 100644
index 000000000..882af202e
--- /dev/null
+++ b/fluxer_app/src/features/i18n/utils/BidiIsolate.ts
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+const CHANNEL_NAME_PATTERN = /(?<![\w/&#])#[a-z][a-z0-9-]*/g;
+
+export function isolateBidi(text: string): string {
+ return `⁨${text}⁩`;
+}
+
+export function isolateChannelNames(text: string): string {
+ return text.replace(CHANNEL_NAME_PATTERN, (channel) => `⁦${channel}⁩`);
+}