Skip to content

Add countdown case #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/kotlin/io/github/goooler/exporter/Res2Xls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlin.io.path.name
import kotlin.io.path.outputStream
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.jdom2.Element
import org.jdom2.Text
import org.jdom2.input.SAXBuilder

fun res2xls(inputPath: String, outputPath: String) {
Expand Down Expand Up @@ -135,9 +136,30 @@ fun res2xls(inputPath: String, outputPath: String) {
internal fun Element.toStringResOrNull(): StringRes? {
if (name != "string") return null
val key = getAttributeValue("name") ?: return null
val containsXlff = content.any { it.toString().contains("xliff") }
val rawText = if (containsXlff) {
buildString {
content.forEach {
when {
it is Text -> append(it.value)
it is Element && it.toString().contains("xliff") -> {
val tag = "xliff:${it.name}"
append("<$tag ")
append(it.attributes.joinToString(" ") { attr -> "${attr.name}=\"${attr.value}\"" })
append(">")
append((it.content.single() as Text).value)
append("</$tag>")
}
else -> append(it.toString())
}
}
}
} else {
text
}
return StringRes(
name = key,
value = text,
value = rawText,
)
}

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/io/github/goooler/exporter/MappingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MappingTest {
StringRes("first", "primo"),
StringRes("forth", "quarto"),
StringRes("seventh", "settimo"),
StringRes("countdown", "\n <xliff:g id=\"time\">%1\$s</xliff:g> fino alle vacanze <xliff:g id=\"end\">%1\$s</xliff:g> all.\n "),
)
assertThat(stringResList).containsExactly(*actual)
}
Expand Down
6 changes: 5 additions & 1 deletion src/test/resources/res/values-it/strings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

<!--Strings-->

<string name="first">primo</string>
<string name="forth">quarto</string>
<string name="seventh">settimo</string>

<string name="countdown">
<xliff:g id="time">%1$s</xliff:g> fino alle vacanze <xliff:g id="end">%1$s</xliff:g> all.
</string>

<!--Plurals-->

<plurals name="apples">
Expand Down
6 changes: 5 additions & 1 deletion src/test/resources/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

<!--Strings-->

Expand All @@ -11,6 +11,10 @@

<string name="sixth" translatable="false">Sixth</string>

<string name="countdown">
<xliff:g id="time" example="5 days">%1$s</xliff:g> until holiday
</string>

<!--Plurals-->

<plurals name="apples">
Expand Down
Loading