You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Translation.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -262,3 +262,82 @@ When building an internationalized app with react-admin, the usual workflow is t
262
262
263
263
Check [the translation setup documentation](./TranslationSetup.md) to understand how to build your own translation file, the [list of available translations](./TranslationLocales.md) to find a translation for your language, and [Translating the UI](./TranslationTranslating.md) to understand how to translate react-admin commponents.
264
264
265
+
## Translating Values
266
+
267
+
Beyond the UX, you may need to translate values in your data. For instance, you may want to display a translated label for a status field, or a translated name for a category.
268
+
269
+
This implies that your data model stores the translations in a way that can be used by the UI. The advised solution is to store the translations as a JSON object in the data itself. For example, a Category resource could have a `name` field that contains the translations for each locale:
270
+
271
+
```json
272
+
{
273
+
"id": 1,
274
+
"name": {
275
+
"en": "Shoes",
276
+
"fr": "Chaussures"
277
+
}
278
+
}
279
+
```
280
+
281
+
If you follow this data structure, you can use special fields and inputs to display and edit the translated values.
282
+
283
+
-[`<TranslatableField>`](./TranslatableFields.md) lets you display all the translations for a field in a single component.
Check out the documentation for [Translatable Fields](./TranslatableFields.md) and [Translatable Inputs](./TranslatableInputs.md) for more details.
314
+
315
+
## Localization
316
+
317
+
For numeric and temporal values, react-admin benefits from the Single-Page Application architecture. As the application executes in the browser, it uses the browser's locale by default to format numbers and dates.
318
+
319
+
For instance, the `<DateField>` renders the date in the user's locale, using the `Intl.DateTimeFormat`API.
320
+
321
+
```tsx
322
+
<DateField source="published_at" />
323
+
// renders the record { id: 1234, published_at: new Date('2017-04-23') } as
324
+
<span>4/23/2017</span>
325
+
```
326
+
327
+
You can force a specific locale by passing the `locale` prop to the field:
0 commit comments