1

In my Flutter Project I'm using the package easy_localization (https://pub.dev/packages/easy_localization).

I want to use Strings like this: This is my Test String.\nIt is supposed to be separated by a new line!.

easy_localization is ignoring the \n and simply shows it as the characters \n and not doing a real new line. A flutter string usually knows what is meant by a \n and interpret it correct.

How do I archive that a \n still get's interpreted as a new line?

Edit:

My localization files are xml files that are kinda like this:

<?xml version="1.0" encoding="UTF-8" ?>
<root>
      <my_string_key>This is my Test String.\nIt is ... by a new line!</my_string_key>
</root>

And I call it somewhere as tr("my_string_key")

Edit:

My Solution now is just that I created a file my_localizer.dart that only got this function:

String myTr(String key) { return tr(key).replaceAll("\\n", "\n"); }

I could import it at the files that I needed it and can use it exactly like the original tr():

myTr("my_string_key")

F.M.
  • 630
  • 1
  • 5
  • 18

0 Answers0