diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/paramConversionUtil.kt b/backend/data/src/main/kotlin/io/tolgee/formats/paramConversionUtil.kt index 407454d1d0..b6ddf213e1 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/paramConversionUtil.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/paramConversionUtil.kt @@ -39,7 +39,7 @@ fun convertMessage( return message.toConvertorResult() } if (!convertPlaceholders || convertorFactory == null) { - return message.escapeIcu(true).toConvertorResult() + return message.escapeIcu(isInPlural).toConvertorResult() } val convertor = convertorFactory() diff --git a/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt b/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt index 68358995f7..8316fd3f0f 100644 --- a/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt @@ -39,6 +39,50 @@ class PoToICUConverterTest { ) } + @Test + fun `php plurals with hashtags works`() { + val result = + getPhpConvertor().convert( + rawData = + mapOf( + 0 to "Petr má jeden znak #.", + 1 to "Petr má %d znaky #.", + 2 to "Petr má %d znaků #.", + ), + languageTag = "cs", + convertPlaceholders = true, + ).message + assertThat(result).isEqualTo( + "{0, plural,\n" + + "one {Petr má jeden znak '#'.}\n" + + "few {Petr má # znaky '#'.}\n" + + "other {Petr má # znaků '#'.}\n" + + "}", + ) + } + + @Test + fun `php plurals with hashtags and disabled placeholders works`() { + val result = + getPhpConvertor().convert( + rawData = + mapOf( + 0 to "Petr má jeden znak #.", + 1 to "Petr má %d znaky #.", + 2 to "Petr má %d znaků #.", + ), + languageTag = "cs", + convertPlaceholders = false, + ).message + assertThat(result).isEqualTo( + "{value, plural,\n" + + "one {Petr má jeden znak '#'.}\n" + + "few {Petr má %d znaky '#'.}\n" + + "other {Petr má %d znaků '#'.}\n" + + "}", + ) + } + private fun getPhpConvertor() = PoToIcuMessageConvertor { PhpToIcuPlaceholderConvertor() } @Test @@ -48,6 +92,24 @@ class PoToICUConverterTest { assertThat(result).isEqualTo("hello this is string {0}, this is digit {1, number}") } + @Test + fun `php message with hashtag works`() { + val result = + getPhpConvertor().convert("hello this is hashtag # and it should not be escaped", "en").message + assertThat(result).isEqualTo("hello this is hashtag # and it should not be escaped") + } + + @Test + fun `php message with hashtag and disabled placeholders works`() { + val result = + getPhpConvertor().convert( + "hello this is hashtag # and it should not be escaped", + "en", + convertPlaceholders = false, + ).message + assertThat(result).isEqualTo("hello this is hashtag # and it should not be escaped") + } + @Test fun testPhpMessageEscapes() { val result =