Import from YAML_RUBY handles percent signs (`%`) incorrectly when ICU is enabled
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:
- 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: "%"
- Visit the translations page and see that "%d" has been treated as a decimal placeholder:
- 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.
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.
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:
- Move time/date format translations to a separate file/namespace that's not uploaded to Tolgee (e.g. formats.en.yml).
- 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 differentsedversion 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'"
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! :)