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

Import from YAML_RUBY handles percent signs (`%`) incorrectly when ICU is enabled

Open apauly opened this issue 8 months ago • 3 comments

Describe the bug When the ICU conversion is active, single percent signs (%) will be interpreted and escaped or treated as placeholder even when they are not part or a placeholder like %{variable}.

To Reproduce Steps to reproduce the behavior:

  1. In a blank new project with ICU conversion enabled, upload the following file en.yml:
en:
  key_1: "Edit %{model}"
  some_date_fornat: "%a, %d. %B %Y"
  some_unit: "%"
  1. Visit the translations page and see that "%d" has been treated as a decimal placeholder:
Image
  1. Download the translations and see additional percent signs:
en:
  key_1: "Edit %{model}"
  some_date_fornat: "%%a, %2$d. %%B %%Y"
  some_unit: "%%"

Expected behavior Percent signs should only be interpreted when they are part of an actual placeholder, e.g. %{variable}. With the example from above, the downloaded file should look like this:

en:
  key_1: "Edit %{model}"
  some_date_fornat: "%a, %d. %B %Y"
  some_unit: "%"

Versions and environment

  • Tolgee Platform version: v3.113.2
  • Environment: Using Docker image tolgee/tolgee:v3.113.2

Additional context Only workaround I've found so far is to either disable ICU conversion completely or to move the affected translations to a separate file that is not uploaded to tolgee.

apauly avatar Apr 04 '25 08:04 apauly

Hello!

Thanks for letting us know.

Currently, this is expected behavior, but we plan to add the option to not escape the %.

I think @Anty0 already knows about the second issue related to this. So I am assigning it to him.

JanCizmar avatar Apr 07 '25 08:04 JanCizmar

Hi @JanCizmar!

Thanks for the feedback 👍. Let me know if I can support with some testing or providing more input on this.

If somebody else stumbles across this, our current workaround consists of two steps:

  1. Move time/date format translations to a separate file/namespace that's not uploaded to Tolgee (e.g. formats.en.yml).
  2. As the other translations might still contain a percent sign, we added this small command to replace %% with % after pulling (using docker to get around different sed version on macOS/Linux):
docker run --rm \
  --volume ./config/locales:/config/locales \
  -it node bash -c "find ./config/locales -name '*.*.yml' | xargs -L1 sed -i 's/%%/%/g'"

apauly avatar Apr 07 '25 09:04 apauly

Hi @apauly! Thank you for the report and the detailed workaround!

I believe the related issue is #2818. Although the issue refers specifically to Apple formats, the same code handles all C-like placeholders.

It's on my list to address, but I won't be able to work on it until the end of the current cycle. I will let you know once I have something for you to test! :)

Anty0 avatar Apr 08 '25 10:04 Anty0