diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescper.kt b/backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescaper.kt similarity index 98% rename from backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescper.kt rename to backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescaper.kt index f25d640c43..ecf8606f0c 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescper.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/escaping/IcuUnescaper.kt @@ -3,7 +3,7 @@ package io.tolgee.formats.escaping /** * It escapes controlling characters in ICU message, so it's not interpreted when in comes from other formats */ -class IcuUnescper( +class IcuUnescaper( private val input: String, private val isPlural: Boolean = false, ) { diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/pluralFormsUtil.kt b/backend/data/src/main/kotlin/io/tolgee/formats/pluralFormsUtil.kt index 1c946fe93e..f6fef8094b 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/pluralFormsUtil.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/pluralFormsUtil.kt @@ -2,7 +2,7 @@ package io.tolgee.formats import com.ibm.icu.text.PluralRules import io.tolgee.formats.escaping.ForceIcuEscaper -import io.tolgee.formats.escaping.IcuUnescper +import io.tolgee.formats.escaping.IcuUnescaper import io.tolgee.formats.escaping.PluralFormIcuEscaper import io.tolgee.util.nullIfEmpty @@ -257,7 +257,7 @@ fun String.forceEscapePluralForms(): MessageConvertorResult? { */ fun String.unescapePluralForms(): String? { val forms = getPluralForms(this) - val unescaped = forms?.forms?.mapValues { IcuUnescper(it.value, isPlural = true).unescaped } + val unescaped = forms?.forms?.mapValues { IcuUnescaper(it.value, isPlural = true).unescaped } return unescaped?.toIcuPluralString(optimize = false, argName = forms.argName) } diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/po/out/IcuToPoMessageConvertor.kt b/backend/data/src/main/kotlin/io/tolgee/formats/po/out/IcuToPoMessageConvertor.kt index f74aeea69d..89362b82f3 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/po/out/IcuToPoMessageConvertor.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/po/out/IcuToPoMessageConvertor.kt @@ -5,7 +5,7 @@ import com.ibm.icu.text.PluralRules.FixedDecimal import com.ibm.icu.util.ULocale import io.tolgee.formats.FromIcuPlaceholderConvertor import io.tolgee.formats.MessageConvertorFactory -import io.tolgee.formats.escaping.IcuUnescper +import io.tolgee.formats.escaping.IcuUnescaper import io.tolgee.formats.getPluralDataOrNull import io.tolgee.formats.getULocaleFromTag import io.tolgee.formats.pluralData.PluralData @@ -69,7 +69,7 @@ class IcuToPoMessageConvertor( val plurals = languagePluralData.examples.map { val form = forms[it.plural] ?: OTHER_KEYWORD - it.plural to ((formsResult[form] ?: formsResult[OTHER_KEYWORD])?.forceUnescape() ?: "") + it.plural to ((formsResult[form] ?: formsResult[OTHER_KEYWORD])?.forceUnescapePluralForm() ?: "") }.sortedBy { it.first }.map { it.second }.toList() return plurals @@ -93,9 +93,9 @@ class IcuToPoMessageConvertor( }.toMap() } - private fun String.forceUnescape(): String { + private fun String.forceUnescapePluralForm(): String { if (!projectIcuPlaceholdersSupport) { - return IcuUnescper(this).unescaped + return IcuUnescaper(this, isPlural = true).unescaped } return this } diff --git a/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/IcuUnescaperTest.kt b/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/IcuUnescaperTest.kt index b11387e6aa..f5d0feec1e 100644 --- a/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/IcuUnescaperTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/IcuUnescaperTest.kt @@ -1,18 +1,18 @@ package io.tolgee.unit.formats.escaping -import io.tolgee.formats.escaping.IcuUnescper +import io.tolgee.formats.escaping.IcuUnescaper import io.tolgee.testing.assert import org.junit.jupiter.api.Test class IcuUnescaperTest { @Test fun `it escapes`() { - IcuUnescper("'{hello}', my friend!").unescaped.assert.isEqualTo("{hello}, my friend!") + IcuUnescaper("'{hello}', my friend!").unescaped.assert.isEqualTo("{hello}, my friend!") } @Test fun `it escapes apostrophes`() { - IcuUnescper( + IcuUnescaper( "we are not entering escaped section: '''' " + "so it doesn't ' have to be doubled. " + "This sequence: '{' should be immediately closed", @@ -25,7 +25,7 @@ class IcuUnescaperTest { @Test fun `it works for weird case`() { - IcuUnescper( + IcuUnescaper( "'What ' complex '''' '{' string # ", false, ).unescaped.assert.isEqualTo("'What ' complex '' { string # ") @@ -34,13 +34,13 @@ class IcuUnescaperTest { @Test fun `removes the escape char on end of string`() { val escaped = "Another ''''' more complex ' '''{ string }''' with many weird '} cases ''''}'" - IcuUnescper(escaped, false) + IcuUnescaper(escaped, false) .unescaped.assert.isEqualTo("Another ''' more complex ' '{ string }' with many weird } cases ''}") } @Test fun `it it escapes escaped`() { - IcuUnescper( + IcuUnescaper( "'''{'", false, ).unescaped.assert.isEqualTo("'{") @@ -48,7 +48,7 @@ class IcuUnescaperTest { @Test fun `it escapes plurals`() { - IcuUnescper( + IcuUnescaper( "What a '#' plural form", isPlural = true, ).unescaped.assert.isEqualTo("What a # plural form") @@ -56,7 +56,7 @@ class IcuUnescaperTest { @Test fun `it unescapes inner sequence correctly`() { - IcuUnescper( + IcuUnescaper( "'{ '' 'lakjsa'.", isPlural = true, ).unescaped.assert.isEqualTo("{ ' lakjsa'.") diff --git a/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/TwoWayEscapingTest.kt b/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/TwoWayEscapingTest.kt index 46e179391d..cc3c487171 100644 --- a/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/TwoWayEscapingTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/unit/formats/escaping/TwoWayEscapingTest.kt @@ -1,7 +1,7 @@ package io.tolgee.unit.formats.escaping import io.tolgee.formats.escaping.ForceIcuEscaper -import io.tolgee.formats.escaping.IcuUnescper +import io.tolgee.formats.escaping.IcuUnescaper import io.tolgee.testing.assert import org.junit.jupiter.api.Test @@ -36,7 +36,7 @@ class TwoWayEscapingTest { plural: Boolean, ) { val escaped = ForceIcuEscaper(string, plural).escaped - val unescaped = IcuUnescper(escaped, plural).unescaped + val unescaped = IcuUnescaper(escaped, plural).unescaped unescaped.assert.describedAs( "\n\nInput:\n$string \n\nEscaped:\n$escaped \n\nUnescpaed: \n$unescaped", ).isEqualTo(string)