Home > Enterprise >  Flutter rich content localization
Flutter rich content localization

Time:10-11

The package intl exists to localize the flutter application but the Intl.message only returns String

How can I have a rich content localization?

  1. Hello $name! , and make only $name bold, Consider that the order of hello and $name can be different in different languages
  2. I read terms of services and accepted it , and link only terms of services part
  3. in [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, or days is before and in 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.

  • Related