Skip to content

Commit 7f13f2f

Browse files
authored
Improve i18n example
Previously the code listed in the i18n example handed over an incorrect 'translate' function to JSON Forms. This is now fixed and the naming improved.
1 parent 5784a1b commit 7f13f2f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

content/docs/i18n.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ https://github.com/eclipsesource/jsonforms/issues/1826
1717
The translate functionality of JSON Forms is integrated into the core component.
1818
In order to translate JSON Forms, you need to set a translation function and provide it to the JSON Forms component:
1919
```ts
20-
const translator = (key, defaultMessage) => {
21-
console.log(`Key: ${key}, Default Message: ${defaultMessage}`);
20+
const createTranslator = (locale) => (key, defaultMessage) => {
21+
console.log(`Locale: ${locale}, Key: ${key}, Default Message: ${defaultMessage}`);
2222
return defaultMessage;
2323
};
2424

2525
const [locale, setLocale] = useState<'de'|'en'>('de');
26-
const translation = useMemo(() => translator(locale), [locale]);
26+
const translation = useMemo(() => createTranslator(locale), [locale]);
2727

2828
<JsonForms
2929
i18n={{locale: locale, translate: translation}}

0 commit comments

Comments
 (0)