Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Tokenizer): label the inline create row from the catalog (#9029)

nynexman44646700c2492342
diff --git a/.changeset/tokenizer-create-row-i18n.md b/.changeset/tokenizer-create-row-i18n.md
new file mode 100644
index 0000000000..ba4fa29631
--- /dev/null
+++ b/.changeset/tokenizer-create-row-i18n.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Tokenizer: the inline create row now takes its `Create "…"` label from the `@astryx.tokenizer.create` message, the same one the bottom sheet uses, so it follows the provider's locale instead of always reading in English. Fixes #8931.
+
+@nynexman4464
diff --git a/packages/core/locales/en.json b/packages/core/locales/en.json
index a0e946101a..22f0a6065d 100644
--- a/packages/core/locales/en.json
+++ b/packages/core/locales/en.json
@@ -1693,7 +1693,7 @@
},
"@astryx.tokenizer.create": {
"defaultMessage": "Create \"{value}\"",
- "description": "Label of the create row inside a Tokenizer's bottom sheet when `hasCreate` is set and the typed text matches no existing item. `{value}` is the typed text, e.g. `Create \"Marketing\"`."
+ "description": "Label of a Tokenizer's create row, in the inline menu and the bottom sheet, when `hasCreate` is set and the typed text matches no existing item. `{value}` is the typed text, e.g. `Create \"Marketing\"`."
},
"@astryx.tokenizer.add": {
"defaultMessage": "Add",
diff --git a/packages/core/src/Tokenizer/Tokenizer.test.tsx b/packages/core/src/Tokenizer/Tokenizer.test.tsx
index 4bd14e3e54..07a6542f84 100644
--- a/packages/core/src/Tokenizer/Tokenizer.test.tsx
+++ b/packages/core/src/Tokenizer/Tokenizer.test.tsx
@@ -723,6 +723,54 @@ describe('Tokenizer', () => {
bootstrap: () => [],
};
+ it('labels the inline create row from the catalog, following the locale', async () => {
+ const overrides = {
+ de: {'@astryx.tokenizer.create': '„{value}“ erstellen'},
+ };
+ const {rerender} = render(
+ <InternationalizationProvider locale="de" overrides={overrides}>
+ <Tokenizer
+ label="Obst"
+ searchSource={emptySource}
+ value={[]}
+ onChange={() => {}}
+ hasCreate
+ debounceMs={0}
+ />
+ </InternationalizationProvider>,
+ );
+ await act(async () => {
+ fireEvent.change(screen.getByRole('combobox'), {
+ target: {value: 'Kiwi'},
+ });
+ });
+ await act(async () => {
+ await new Promise(r => setTimeout(r, 50));
+ });
+ expect(screen.getByText('„Kiwi“ erstellen')).toBeInTheDocument();
+ expect(screen.queryByText('Create "Kiwi"')).not.toBeInTheDocument();
+
+ rerender(
+ <InternationalizationProvider locale="en" overrides={overrides}>
+ <Tokenizer
+ label="Obst"
+ searchSource={emptySource}
+ value={[]}
+ onChange={() => {}}
+ hasCreate
+ debounceMs={0}
+ />
+ </InternationalizationProvider>,
+ );
+ // The row is derived per query, so the next query takes the new locale.
+ await act(async () => {
+ fireEvent.change(screen.getByRole('combobox'), {
+ target: {value: 'Kiwis'},
+ });
+ });
+ expect(await screen.findByText('Create "Kiwis"')).toBeInTheDocument();
+ });
+
it('still offers Create below minQueryLength, and does not search', async () => {
// The threshold exists to avoid a fetch too broad to be worth making.
// Creating costs no fetch, so a field that can create `QA` should not
diff --git a/packages/core/src/Tokenizer/Tokenizer.tsx b/packages/core/src/Tokenizer/Tokenizer.tsx
index ac5df922b6..e31b63816d 100644
--- a/packages/core/src/Tokenizer/Tokenizer.tsx
+++ b/packages/core/src/Tokenizer/Tokenizer.tsx
@@ -1111,12 +1111,12 @@ export function Tokenizer<T extends SearchableItem>({
return [
{
id: `${CREATABLE_ID_PREFIX}${trimmed}`,
- label: `Create "${trimmed}"`,
+ label: t('@astryx.tokenizer.create', {value: trimmed}),
auxiliaryData: {__createdValue: trimmed},
} as unknown as T,
];
},
- [hasCreate, selectedIds, selectedLabels],
+ [hasCreate, selectedIds, selectedLabels, t],
);
const emptySource: SearchSource<T> = useMemo(