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

Compose Multiplatform export uses wrong positonal arguments placeholder

Open aschulz90 opened this issue 7 months ago • 5 comments

Describe the bug Follow up to #2397. As described in the issue, positional arguments are wrongly exported for Compose Multiplatform.

To Reproduce Steps to reproduce the behavior:

  1. Add key with text Hello, I'm {name} {surname}
  2. Export for Compose Multiplatform
  3. String is exported as <string name="test_icu">Hello, I'm %s %s</string>

Expected behavior Text is exported with indexed positional arguments, e.g.: <string name="test_icu">Hello, I'm %1$s %2$s</string>

Versions and environment

  • Tolgee Platform version: v3.114.4

aschulz90 avatar May 05 '25 16:05 aschulz90

Hi! Thank you for the report! Sorry @mauriziofaleo, I missed the comment in the previous issue.

I remember discussing handling named arguments with colleagues, and we decided to leave them unresolved. As long as you use numbered ICU placeholders, Tolgee will correctly convert them. However, to properly implement the numbering of named arguments, because their order can change between translations, we would need to read and parse the base language translation, find the correct order of named placeholders, and then keep that order for other languages. Unfortunately, the current export system isn't ready for this and can't provide this info during the export process.

For people who need to export to this format, there are two options: Use exclusively numbered ICU placeholders or turn off ICU placeholders.

I'll try to bring this up again with colleagues. We will try to figure out a more straightforward way of dealing with this. ^^

Anty0 avatar May 07 '25 13:05 Anty0

Thank you for looking into this @Anty0!

We're also implementing Compose Multiplatform and have encountered the same issue. All our placeholders are completely broken.

Example:

  • Source text: Hello, I'm {name}!
  • Current COMPOSE_XML export: <string name="key_name">Hello, I'm %s!</string>
  • Expected export: <string name="key_name">Hello, I'm %1$s!</string>

The core problem is that Tolgee exports placeholders as %s instead of the indexed format %1$s that Compose Multiplatform requires (as documented here).

Proposed solution: Instead of returning %s for placeholders, could you return them in indexed format like %1$s ignoring the order? This would make the exported strings compatible with Compose Multiplatform out of the box. Although the order may still be incorrect of course.

soldt avatar Aug 15 '25 11:08 soldt

Hi @Anty0, Do you have any progress with this issue? This problem causes a lot of difficulties for us, we can't use strings exported from Tolgee as expected. A good solution for us would be to export a string like Hello {name} {surname} as Hello %1$s %2$s That would work for us

finchatticus avatar Sep 11 '25 12:09 finchatticus

Hi @soldt! We considered doing something like that, but we didn't because we wouldn't be able to change it later—if people start using named parameters and we change how we export them, it could break their apps. The only way I see this being resolved is by implementing it properly, as I described in my last message.

Anty0 avatar Sep 11 '25 17:09 Anty0

Hi @finchatticus! It's on my list, but since it requires changes to the export system, it might not fit into the regular bug-fixing window. However, quite a few people have recently shown support for this issue. Also, we've just released the Android SDK, which adds some momentum to this issue as well. I can't promise anything, but I'll try to bring it up during the next planning.

Anty0 avatar Sep 11 '25 17:09 Anty0