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.

Share:
230
WebMaster
Author by

WebMaster

I'm a fullstack developer

Updated on January 01, 2023

Comments

  • WebMaster
    WebMaster over 1 year

    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]
  • WebMaster
    WebMaster over 2 years
    I 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
    moneer alhashim over 2 years
    There are no advanced options as you know. So as you probably know you can use RichText to work around this.
  • WebMaster
    WebMaster over 2 years
    Ok thanks, I just wanted to be sure
  • Sander Roest
    Sander Roest over 2 years
    I use this mark_down package to add some simple styles to localised strings. pub.dev/packages/flutter_markdown