From 5b52d0e173c29741075f0f36b70ddc8a885ea7e0 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Thu, 28 Dec 2023 22:53:37 +0700 Subject: [PATCH] android, desktop: localization script enchancement (#3616) --- apps/multiplatform/common/build.gradle.kts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/multiplatform/common/build.gradle.kts b/apps/multiplatform/common/build.gradle.kts index 4d2eeca2ee..3b6975638a 100644 --- a/apps/multiplatform/common/build.gradle.kts +++ b/apps/multiplatform/common/build.gradle.kts @@ -154,8 +154,10 @@ afterEvaluate { val endStringRegex = Regex("[ ]*") val endTagRegex = Regex("]*>.*(<|>).*|[^>]*>.*(<|>).*") + val fontLtGtRegex = Regex("[^>]*>.*<font[^>]*>.*</font>.*") + val unbracketedColorRegex = Regex("color=#[abcdefABCDEF0-9]{3,6}") val correctHtmlRegex = Regex("[^>]*>.*.*.*|[^>]*>.*.*.*|[^>]*>.*.*.*|[^>]*>.*]*>.*.*") - val possibleFormat = listOf("s", "d", "1\$s", "1\$d", "2s", "f") + val possibleFormat = listOf("s", "d", "1\$s", "2\$s", "3\$s", "4\$s", "1\$d", "2\$d", "3\$d", "4\$d", "2s", "f") fun String.id(): String = replace("' } - if (countOfStartTag != countOfEndTag || countOfStartTag != endTagRegex.findAll(this).count() * 2 || !correctHtmlRegex.matches(this)) { + val prepared = if (fontLtGtRegex.matches(this) || unbracketedColorRegex.containsMatchIn(this)) { + replace("<", "<").replace(">", ">").replace(unbracketedColorRegex) { it.value.replace("color=#", "color=\"#") + "\"" } + } else this + val countOfStartTag = prepared.count { it == '<' } + val countOfEndTag = prepared.count { it == '>' } + if (countOfStartTag != countOfEndTag || countOfStartTag != endTagRegex.findAll(prepared).count() * 2 || !correctHtmlRegex.matches(prepared)) { if (debug) { println("Wrong string:") println(this) @@ -206,7 +215,7 @@ afterEvaluate { throw Exception("Wrong string: $this \nin $filepath") } } - val res = replace(startStringRegex) { it.value + "" + it.value } + val res = prepared.replace(startStringRegex) { it.value + "" + it.value } if (debug) { println("Changed string:") println(this)