The package intl
exists to localize the flutter application but the Intl.message
only returns String
How can I have a rich content localization?
Hello $name!
, and make only$name
bold, Consider that the order of hello and $name can be different in different languagesI read terms of services and accepted it
, and link onlyterms of services
partin [TEXT_INPUT] days
, the [TEXT_INPUT] has a text after and a text before, but in some languages there is no 2 text, just one text after or before, ordays
is before andin
is after[TEXT_INPUT]
CodePudding user response:
Here is an example of how you can inject variables into your translation.
"hello_name": "Hello {name}",
"@hello_name": {
"placeholders": {
"name": {
"type": "String"
}
}
},
This will generate a function hello_name
for you to pass name
There is no styling support but if you need it then just don't use placeholders
like in the above example and have your text be separate and style it using RichText
where you specify what parts of your text need to have what styling. You don't need to worry about directionality as it will be handled for you depending on your local.