Flutter rich content localization
230
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.
Comments
-
WebMaster over 1 year
The package
intl
exists to localize the flutter application but theIntl.message
only returnsString
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]
-
WebMaster over 2 yearsI know it intl has inject variables, the problem is there is no advanced options for variable, see my 3rd example, we cannot have a text field variable
-
moneer alhashim over 2 yearsThere are no advanced options as you know. So as you probably know you can use
RichText
to work around this. -
WebMaster over 2 yearsOk thanks, I just wanted to be sure
-
Sander Roest over 2 yearsI use this mark_down package to add some simple styles to localised strings. pub.dev/packages/flutter_markdown