Localize Dynamic Forms with Lingui #1947
-
I have a dynamic form generator which accepts JSON object, and then creates a form with its fields. JSON objects consist of separate objects each describing form fields. I am trying to use Lingui to localize and translate the content of each field, including labels, placeholder, options and error messages. My main problem is that I can't find a way to translate variables used to represent content. Here is an example - this is a sample configuration for 2 select fields: {
category: "field",
fieldType: "select",
name: "Type",
label: "Type",
},
{
category: "field",
fieldType: "select",
name: "subtype",
label: "Subtype",
}, And here are my approaches: <label>{label && <Trans>{label}</Trans>}</label>
//
<label>{label && t(i18n)`${label}`}</label> Am I missing something or this is not an available feature for the moment? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
https://lingui.dev/tutorials/react-patterns#lazy-translations import {msg} from "@lingui/macro";
import {Trans} from "@lingui/react";
const defs = [
{
category: "field",
fieldType: "select",
name: "Type",
label: msg`Type`,
},
{
category: "field",
fieldType: "select",
name: "subtype",
label: msg`Subtype`,
},
]
// usage in jsx
<label>{label && <Trans id={label.id}/>}</label>; |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a set of Select Option labels that come from BackEnd. Here is an example: Response from backend:
my trial was :
but it is not working? |
Beta Was this translation helpful? Give feedback.
https://lingui.dev/tutorials/react-patterns#lazy-translations