Skip to content

Commit ed31fba

Browse files
authored
Fix parsing more than 9 placeholders with order (#67)
1 parent bc74550 commit ed31fba

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
### Security
3535
- No security issues fixed!
3636

37+
## [3.4.1] - 2023-07-13
38+
### Fixed
39+
- Fix parsing of texts with more than 9 placeholders.
40+
3741
## [3.4.0] - 2023-05-08
3842
### Added
3943
- Add new `unescapeHtmlTags` flag to enable or disable HTML unescaping from strings.
@@ -470,7 +474,8 @@ res_dir_path -> resDirPath
470474
### Added
471475
- Initial release.
472476

473-
[Unreleased]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.0...HEAD
477+
[Unreleased]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.1...HEAD
478+
[3.4.1]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.4.0...3.4.1
474479
[3.4.0]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.3.0...3.4.0
475480
[3.3.1]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.3.0...3.3.1
476481
[3.3.0]: https://github.com/hyperdevs-team/poeditor-android-gradle-plugin/compare/3.2.0...3.3.0

src/main/kotlin/com/hyperdevs/poeditor/gradle/xml/XmlPostProcessor.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.hyperdevs.poeditor.gradle.xml
2020

2121
import com.hyperdevs.poeditor.gradle.ktx.toAndroidXmlString
2222
import com.hyperdevs.poeditor.gradle.ktx.toStringsXmlDocument
23-
import com.hyperdevs.poeditor.gradle.ktx.unescapeHtmlTags
2423
import com.hyperdevs.poeditor.gradle.utils.ALL_REGEX_STRING
2524
import org.w3c.dom.*
2625

@@ -31,7 +30,7 @@ import org.w3c.dom.*
3130
class XmlPostProcessor {
3231
companion object {
3332
private val DEFAULT_ENCODING = Charsets.UTF_8
34-
private val VARIABLE_REGEX = Regex("""\{\d?\{(.*?)\}\}""")
33+
private val VARIABLE_REGEX = Regex("""\{(\d*)\{(.*?)\}\}""")
3534

3635
private const val TAG_RESOURCES = "resources"
3736
private const val TAG_STRING = "string"
@@ -82,9 +81,10 @@ class XmlPostProcessor {
8281
// throw an exception
8382

8483
// If the placeholder contains an ordinal, use it: {2{pages_count}} -> %2$s
85-
val match = matchResult.groupValues[0]
86-
if (Character.isDigit(match[1])) {
87-
"%${match[1]}\$s"
84+
val fullMatch = matchResult.groupValues[0]
85+
val placeholderVaraibleOrder = matchResult.groupValues[1]
86+
if (placeholderVaraibleOrder.toIntOrNull() != null) {
87+
"%$placeholderVaraibleOrder\$s"
8888
} else { // If not, use "1" as the ordinal: {{pages_count}} -> %1$s
8989
"%1\$s"
9090
}

src/test/kotlin/com/hyperdevs/poeditor/gradle/xml/XmlPostProcessorTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ class XmlPostProcessorTest {
8888
xmlPostProcessor.formatTranslationString("Hello {{name}}. How are you {{name}}?"))
8989
Assert.assertEquals("Hello %1\$s. This is your score: %2\$s",
9090
xmlPostProcessor.formatTranslationString("Hello {1{name}}. This is your score: {2{score}}"))
91+
92+
Assert.assertEquals("Hello %1\$s %2\$s %3\$s %4\$s %5\$s %6\$s %7\$s %8\$s %9\$s %10\$s %11\$s",
93+
xmlPostProcessor.formatTranslationString(
94+
"Hello {1{name}} {2{name}} {3{name}} {4{name}} {5{name}} " +
95+
"{6{name}} {7{name}} {8{name}} {9{name}} {10{name}} {11{name}}"
96+
)
97+
)
9198
}
9299

93100
@Test

0 commit comments

Comments
 (0)