From fbb8ed97a5c2c7f9417781c0aebe378f2b1b66c2 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Fri, 12 Jul 2024 11:37:51 +0200 Subject: [PATCH] Translator comments to have empty translation spots --- .../org/jeudego/pairgoth/util/Translator.kt | 25 +++++++++++++++---- .../src/main/webapp/tour-information.inc.html | 2 +- .../src/main/webapp/tour-parameters.inc.html | 1 + .../src/main/webapp/tour-standings.inc.html | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/util/Translator.kt b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/util/Translator.kt index 3c40228..adb3538 100644 --- a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/util/Translator.kt +++ b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/util/Translator.kt @@ -21,12 +21,14 @@ import kotlin.io.path.useDirectoryEntries class Translator private constructor(private val iso: String) { - fun translate(enText: String) = translations[iso]?.get(enText) ?: enText.also { - reportMissingTranslation(enText) - } + fun translate(enText: String) = + translations[iso]?.get(enText) ?: enText.let { + it.replace(Regex("_BLANK_\\w+"), "") + }.also { + reportMissingTranslation(enText) + } fun translate(uri: String, template: Template): Template? { - if (iso == "en") return template val key = Pair(uri, iso) var translated = translatedTemplates[key] if (translated != null && translated.lastModified < template.lastModified) { @@ -39,7 +41,11 @@ class Translator private constructor(private val iso: String) { if (translated == null) { translated = template.clone() as Template val data: SimpleNode = translated!!.data as SimpleNode - translateNode(data) + if (iso == "en") { + stripComments(data) + } else { + translateNode(data) + } translatedTemplates[key] = translated!! } } @@ -47,6 +53,15 @@ class Translator private constructor(private val iso: String) { return translated } + private fun stripComments(node: SimpleNode) { + if (node is ASTText) { + node.text = node.text.replace(Regex("_BLANK_\\w+"), "") + } + else for (i in 0 until node.jjtGetNumChildren()) { + stripComments(node.jjtGetChild(i) as SimpleNode) + } + } + private fun translateNode(node: SimpleNode, ignoringInput: String? = null): String? { var ignoring = ignoringInput if (node is ASTText) translateFragments(node.text, ignoring).let { diff --git a/view-webapp/src/main/webapp/tour-information.inc.html b/view-webapp/src/main/webapp/tour-information.inc.html index 6d58861..b7a43aa 100644 --- a/view-webapp/src/main/webapp/tour-information.inc.html +++ b/view-webapp/src/main/webapp/tour-information.inc.html @@ -281,7 +281,7 @@ Advanced parameters