Search code examples
flutterdartinternationalization

Flutter rich content localization


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]

Solution

  • The slang package has built-in rich text support.

    It will look like this:

    {
      "myRichText(rich)": "Welcome {name}"
    }
    
    Widget a = Text.rich(t.myRichText(
      // Show name in blue color
      name: TextSpan(text: 'Tom', style: TextStyle(color: Colors.blue)),
    ));