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 only terms 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, or days is before and in is after [TEXT_INPUT]Have a look at the styled_text package. You get to specify the text (content) separately from the formatting, witch allows you to use standard i18n approaches.
Text format is specified as tags wich you can define globally (e.g. in a resource class) and then use everywhere. Sounds like a good solution to me.
Example (from the Readme):
StyledText(
text: 'Test: <bold>bold</bold> text.',
tags: {
'bold': const StyledTextTag(style: const TextStyle(fontWeight: FontWeight.bold)),
},
)
will display like:
Test: bold text.
If you use the i18n package and a resource class instance R for the tags, this might look like:
StyledText(
text: S.testBoldText,
tags: R.styledTextTags,
);
Just keep in mind that the tags need to be preserved in translation.
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)),
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With