feat: Handle <plurals> string resources (#741)
This commit is contained in:
parent
efd1c8e556
commit
d6b36bf976
|
@ -112,10 +112,10 @@ class App : CliktCommand(help = """Move string resources between modules""") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class State {
|
sealed interface State {
|
||||||
Searching,
|
data object Searching : State
|
||||||
Moving,
|
data class Moving(val etag: String) : State
|
||||||
Moved,
|
data object Moved : State
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun moveResource(src: Path, dst: Path, id: String) {
|
private fun moveResource(src: Path, dst: Path, id: String) {
|
||||||
|
@ -130,27 +130,33 @@ class App : CliktCommand(help = """Move string resources between modules""") {
|
||||||
val dstFile = dst / "strings.xml"
|
val dstFile = dst / "strings.xml"
|
||||||
|
|
||||||
val toCopy = mutableListOf<String>()
|
val toCopy = mutableListOf<String>()
|
||||||
var state = State.Searching
|
var state: State = State.Searching
|
||||||
|
|
||||||
srcFile.useLines { srcLines ->
|
srcFile.useLines { srcLines ->
|
||||||
for (srcLine in srcLines) {
|
for (srcLine in srcLines) {
|
||||||
// Moved the resource, copy the remaining lines
|
// Moved the resource, copy the remaining lines
|
||||||
if (state == State.Moved) {
|
if (state is State.Moved) {
|
||||||
tmpSrc.println(srcLine)
|
tmpSrc.println(srcLine)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not the resource we're looking for
|
if (state == State.Searching) {
|
||||||
if (state == State.Searching && !srcLine.contains("""<string name="$id""")) {
|
when {
|
||||||
tmpSrc.println(srcLine)
|
srcLine.contains("""<string name="$id"""") -> state = State.Moving("</string>")
|
||||||
continue
|
srcLine.contains("""<plurals name="$id"""") -> state = State.Moving("</plurals>")
|
||||||
|
else -> {
|
||||||
|
tmpSrc.println(srcLine)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matching resource. Append to dstFile
|
// Matching resource. Append to dstFile
|
||||||
state = State.Moving
|
|
||||||
toCopy.add(srcLine)
|
toCopy.add(srcLine)
|
||||||
|
|
||||||
if (srcLine.contains("</string>")) {
|
if (state !is State.Moving) throw RuntimeException("invalid state, $state")
|
||||||
|
|
||||||
|
if (srcLine.contains((state as State.Moving).etag)) {
|
||||||
if (!dstFile.exists()) createResourceFile(dstFile)
|
if (!dstFile.exists()) createResourceFile(dstFile)
|
||||||
dstFile.useLines { dstLines ->
|
dstFile.useLines { dstLines ->
|
||||||
for (dstLine in dstLines) {
|
for (dstLine in dstLines) {
|
||||||
|
|
Loading…
Reference in New Issue