moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Need ability to handle significant leading or trailing whitespace in strings

Open dalewking opened this issue 4 years ago • 3 comments

Sometimes a String resource needs leading or trailing whitespace for the string and I cannot find any way to handle that with Moko resources.

Adding leading or trailing whitespace in the file actually works and is preserved on the iOS side, but not on the Android side. In normal android string resources to preserve whitespace you surround the string with quotes.

I cannot find a way to define a common string with leading or trailing whitespace that is preserved for both iOS and Android.

One way to do it would be that when generating the Android resource file and the string has leading or trailing whitespace surround it with quotes (actually, you could just always surround it with quotes).

dalewking avatar Feb 05 '21 15:02 dalewking

That would lead to weird and not expected behaviour (from a Android developer perspectiv). I would prefer that whitespaces are trimmed. Like the default implementation of handling in Android.

related to this would be, that creating localization with CDATA produces unexpected newlines.

    <string name="some_key">
        <![CDATA[some content ]]>
</string>

expected some content
actual \nsome content\n

ghost avatar Aug 13 '21 09:08 ghost

Right now (or at least on the older version of this library we are using) if you add leading or trailing whitespace you get different results on iOS and Android. That is not acceptable. So at the minimum it needs to be fixed that you get the same results. That part of this issue is a bug and not an enhancement

But there are cases where you need leading and trailing whitespace to be preserved, so that needs to be supported. Right now the implied intent is that they are always preserved since they are preserved on iOS, but the implementation is inconsistent because the generated Android files includes the whitespace in the generated file, but does not surround it with quotes so that it is preserved.

It is fine to make a change that by default it isn't preserved, but then you need an enhancement to add a way to specify that leading or trailing whitespace should be preserved. Android does this through the use of quotes around the string, which would be a good way to do it or if you wanted to make it an element on the string tag that is fine too.

So as I see it there are 2 possible resolutions to the issue:

  • Go with the philosophy that leading and trailing whitespace is always preserved
    • This requires fixing the Android generator to surround the string with quotes if it has leading or trailing whitespace
  • Go with the philosophy that it is by default not preserved
    • This means that some mechanism must be provided to override this default behavior
      • This also requires fixing the Android generator to surround the string with quotes when it is to be preserved

Either road is acceptable but the current state is not.

dalewking avatar Aug 13 '21 16:08 dalewking

I vote for

Go with the philosophy that it is by default not preserved

Using quotes to preseve whitespaces was always a good and visible way on Android. Preseving whitespaces in XML will lead to unexpected results if you hit auto format and your settings were diffrent from the team.

ghost avatar Aug 16 '21 08:08 ghost