dart-sprintf icon indicating copy to clipboard operation
dart-sprintf copied to clipboard

Wrong formattring in RTL language

Open mishatron opened this issue 6 years ago • 2 comments

Let we have strings in English (LTR) and Hebrew (RTL)

String s = "Well done %s!";
 String t = "! %s כל הכבוד";

So when I use smth like Text(sprintf(s,[userName])); everything is correct. But when Text(sprintf(t,[userName]));

I got "כל הכבוד USER_NAME!". It should be "!USER_NAME כל הכבוד" Maybe it is related to flutter, maybe to library

mishatron avatar Apr 08 '20 14:04 mishatron

Hi @mishatron , So, this might be a flutter thing, but I'm not 100% sure since I don't have any experience with RTL languages.

I tried writing a test to reproduce this:


  test("|! %s כל הכבוד| hello",
      () => expect(sprintf(t, ["hello"]), "! hello כל הכבוד"));

and it passes. and I also just printed the result, which seems to work:

String t = "! %s כל הכבוד";
  print(sprintf(t, ["hello"]));
// ! hello כל הכבוד

However, it might work on my machine because it's set to LTR, and the test might fail if I changed locale? Do you know how I could reproduce it as a test in travis ci? (Would I need to set a locale environment variable?

Naddiseo avatar May 10 '20 19:05 Naddiseo

Firstly locale is important, I tested on the emulator so for me it was not a problem. but I also have thoughts that this issue is connected to flutter sdk (I learned code of library and it is ok), because some strings formatted correctly, some not. so, who knows...

mishatron avatar May 10 '20 19:05 mishatron