Skip to content

Commit 3f703c6

Browse files
committed
refactor(mosaic): nest localization keys under their public component
1 parent 4f2a95d commit 3f703c6

86 files changed

Lines changed: 258 additions & 229 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/mosaic': minor
3+
---
4+
5+
Reorganize localization keys under the component they belong to. Section and dialog strings now nest under their component instead of sitting at the top level, for example `userProfileMfa.label` is now `userProfile.mfa.label`, `membersTableTab.title` is now `organizationProfile.members.list.title`, and `apiKeysTable.search` is now `apiKeys.search`. Email and phone strings moved from `userProfileContact.email` and `userProfileContact.phone` to `userProfile.email` and `userProfile.phone`. Update any `localization` overrides that use the old keys; TypeScript flags each one.

‎packages/mosaic/ARCHITECTURE.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ user-button.styles.ts // `stylex.create` atoms (see the StyleX authoring
208208
model nor the view owns it, and the two cannot drift.
209209

210210
`*.messages.ts` holds strings only, exported as one `<feature>Messages` object
211-
declared `as const` and registered under a namespace in `src/localization/registry.ts`.
212-
Views read their namespace inside the component with `useMessages('userButton')`, so
211+
declared `as const` and mounted in `src/localization/registry.ts` under the public
212+
component it belongs to, such as `userProfile.mfa.backupCodes`. A root is a public
213+
component or a shared block, never a file name. Views read their root inside the
214+
component with `useMessages('userProfile').mfa`, so
213215
the `localization` prop on `MosaicProvider` can replace any string; a module-level
214216
helper takes the messages as a parameter rather than importing them.
215217

‎packages/mosaic/src/features/api-keys/__tests__/api-keys-table.feature.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ describe('APIKeysTable', () => {
247247
<MosaicProvider
248248
localization={{
249249
overrides: {
250-
'apiKeysTable.search': 'Find a key',
251-
'apiKeysTable.expires': 'Expiration: {expiresDate}',
252-
'apiKeysTable.revokeTitle': 'Retirer {name} ?',
250+
'apiKeys.search': 'Find a key',
251+
'apiKeys.expires': 'Expiration: {expiresDate}',
252+
'apiKeys.revokeTitle': 'Retirer {name} ?',
253253
},
254254
}}
255255
>

‎packages/mosaic/src/features/api-keys/api-keys-table.messages.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const apiKeysTableMessages = {
6969
} as const;
7070

7171
export function resolveAPIKeysTableMessages(
72-
catalog: MosaicMessages['apiKeysTable'],
72+
catalog: MosaicMessages['apiKeys'],
7373
subjectKind: APIKeysTableSubjectKind,
7474
overrides?: Partial<APIKeysTableMessages>,
7575
): APIKeysTableMessages {

‎packages/mosaic/src/features/api-keys/api-keys-table.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function SubjectAPIKeysTable({
3838
fallback,
3939
}: APIKeysTableProps) {
4040
const messages = resolveAPIKeysTableMessages(
41-
useMessages('apiKeysTable'),
41+
useMessages('apiKeys'),
4242
isOrganizationId(subject) ? 'organization' : 'user',
4343
overrides,
4444
);

‎packages/mosaic/src/features/api-keys/api-keys-table.types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type APIKeysTableSubjectKind = 'user' | 'organization';
2020

2121
type Strings<T> = { readonly [K in keyof T]: T[K] extends string ? string : Strings<T[K]> };
2222

23-
export type APIKeysTableMessages = Strings<Omit<MosaicMessages['apiKeysTable'], 'noKeysDescription'>> & {
23+
export type APIKeysTableMessages = Strings<Omit<MosaicMessages['apiKeys'], 'noKeysDescription'>> & {
2424
readonly noKeysDescription: string;
2525
};
2626

‎packages/mosaic/src/features/organization-profile/organization-profile-danger-section/organization-profile-danger-section.view.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function OrganizationProfileDangerSectionView({
1717
leave,
1818
destroy,
1919
}: OrganizationProfileDangerSectionViewProps) {
20-
const m = useMessages('organizationProfileDangerSection');
20+
const m = useMessages('organizationProfile').danger;
2121
const locale = useLocale();
2222

2323
if (!leave && !destroy) {
@@ -78,7 +78,7 @@ function DangerRow({
7878
dialogTitle: string;
7979
dialogDescription: string;
8080
}) {
81-
const m = useMessages('organizationProfileDangerSection');
81+
const m = useMessages('organizationProfile').danger;
8282

8383
return (
8484
<Section.Row>

‎packages/mosaic/src/features/organization-profile/organization-profile-members-panel/invitations-table-tab.controller.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function useInvitationsTableController(
1212
): InvitationsTableTabViewProps {
1313
const locale = useLocale();
1414
const roleNames = useMessages('roles');
15-
const m = useMessages('invitationsTableTab');
15+
const m = useMessages('organizationProfile').members.invitations;
1616
const invitations = model.rows.map(({ id, emailAddress, createdAt, role, roleName }) => ({
1717
id,
1818
email: emailAddress,

‎packages/mosaic/src/features/organization-profile/organization-profile-members-panel/invitations-table-tab.skeleton.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function InvitationsTableTabSkeleton({
4444
hasRevoke: boolean;
4545
hasBulkAction: boolean;
4646
}) {
47-
const m = useMessages('invitationsTableTab');
47+
const m = useMessages('organizationProfile').members.invitations;
4848
return (
4949
<div
5050
{...mergeStyleProps(themeProps('invitations-table-tab'), stylex.props(tableTabStyles.root))}

‎packages/mosaic/src/features/organization-profile/organization-profile-members-panel/invitations-table-tab.view.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function InvitationsTableTabView({
3838
isError = false,
3939
onRetry,
4040
}: InvitationsTableTabViewProps) {
41-
const m = useMessages('invitationsTableTab');
41+
const m = useMessages('organizationProfile').members.invitations;
4242
const showPagination = Math.ceil(totalCount / pageSize) > 1;
4343
return (
4444
<>
@@ -136,7 +136,7 @@ function InvitationsTableBody({
136136
onRevokeClick?: (invitation: OrganizationProfileInvitation) => void;
137137
registerTrigger: (id: string) => Ref<HTMLButtonElement>;
138138
}) {
139-
const m = useMessages('invitationsTableTab');
139+
const m = useMessages('organizationProfile').members.invitations;
140140
return (
141141
<Table.Body
142142
items={invitations}

0 commit comments

Comments
 (0)