tolgee-platform icon indicating copy to clipboard operation
tolgee-platform copied to clipboard

Export strings for Compose Multiplatform

Open mauriziofaleo opened this issue 1 year ago • 7 comments

Feature request Strings for Compose Multiplatform need to be stored in an XML file encoded in a similar way to those used by Android, with some minor differences. For this reason, strings exported by Tolgee with the Android exporter are not immediately usable for mobile apps based on Compose Multiplatform and need some manual changes.

The only two differences I've identified are:

  • ' and " should not be escaped. If escaped as Android requires, the \ will be visible to the user. This point has been discussed in the Compose Multiplatform repository here and here, and they provided a confirmation regarding the differences of the two formats.
  • Positional arguments are exported for Android as %s without any indication of the argument number. For Compose Multiplatform, it should be %1$s, %2$s, etc. (source)

Describe the solution you'd like I'd like to have a new export option called "Compose Multiplatform" which reuses the same implementation of the Android exporter, with the two differences I've mentioned before:

  • It does not escape ' and ".
  • It encodes the positional arguments with the position index.

Describe alternatives you've considered The workaround I'm currently using is:

  • Manually replacing \' and \" with ' and " before importing the XML into the codebase.
  • Disabling the ICU Message Format so that I can manually handle the positional arguments in Tolgee.

Additional context If you want to know more about Compose Multiplatform resources, you can check the official doc.

Thank you!

mauriziofaleo avatar Jul 02 '24 16:07 mauriziofaleo

Hey! Thanks! Will look into that!

JanCizmar avatar Jul 06 '24 09:07 JanCizmar

Thank you Jan for considering it! I'm available for any kind of questions you might have!

mauriziofaleo avatar Jul 08 '24 10:07 mauriziofaleo

Another thing is the starting tag: <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

should only be <resources>

for multiplatform

btw i would like this for android as well:

Positional arguments are exported for Android as %s without any indication of the argument number. For Compose Multiplatform, it should be %1$s, %2$s, etc. (source)

Nailik avatar Jul 24 '24 15:07 Nailik

Hey! We will do following:

  • Add the positional for android too, since it removes the warning.
  • Remove the quoting logic for multiplatform files. Do I understand it correctly that there is no quoting logic for compose multiplatform resources?

JanCizmar avatar Jul 25 '24 13:07 JanCizmar

Remove the quoting logic for multiplatform files. Do I understand it correctly that there is no quoting logic for compose multiplatform resources?

Exactly, on Compose Multiplatform we don't need to escape ' and ", so the logic needs to be removed.

mauriziofaleo avatar Jul 26 '24 19:07 mauriziofaleo

Another note, for multiplatform html tags should not be encoded as well. You could test it with AnnotatedString.fromHtml(htmlString), there's also no need to wrap with cdata which removes the need of this android flag for multiplatform (or compose in general when using this approach)

Nailik avatar Aug 05 '24 12:08 Nailik

Another note, for multiplatform html tags should not be encoded as well. You could test it with AnnotatedString.fromHtml(htmlString) ...

@Nailik Hi! Do you have some example files with this edge case? I'm trying to understand the difference. Thanks!

Anty0 avatar Oct 11 '24 14:10 Anty0

@Anty0 @JanCizmar Thank you so much, guys! 👏🏻

I’ve just tested the feature released with v3.89.0 on a project with 420 keys and 4k strings, including some plurals.

' and " should not be escaped. If escaped as Android requires, the \ will be visible to the user. This point has been discussed in the Compose Multiplatform repository https://github.com/JetBrains/compose-multiplatform/issues/4178 and https://github.com/JetBrains/compose-multiplatform/issues/4664, and they provided a confirmation regarding the differences of the two formats.

It now works perfectly.

Positional arguments are exported for Android as %s without any indication of the argument number. For Compose Multiplatform, it should be %1$s, %2$s, etc. (source)

Please note that this issue still occurs. For instance, I added the string Hello, I'm {name} {surname} which was exported as

<string name="test_icu">Hello, I'm %s %s</string>

instead of

<string name="test_icu">Hello, I'm %1$s %2$s</string>

For my use case, it’s not a big deal since I can disable the ICU messages without any side effects. However, for others who need to support multiple platforms, this limitation could be critical.

Have an happy new year!

mauriziofaleo avatar Jan 03 '25 14:01 mauriziofaleo

Please note that this issue still occurs. For instance, I added the string Hello, I'm {name} {surname} which was exported as

Weird! @Anty0 can you please look into that?

JanCizmar avatar Jan 03 '25 16:01 JanCizmar

@mauriziofaleo I'm sorry I didn't respond here! Must have missed the comment. We are tracking this exact issue here now: #3054 I'll see if I can figure out how to deal with this. ^^

Anty0 avatar May 07 '25 13:05 Anty0