Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Jul 30, 2022
1 parent 373f305 commit fc45bd0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
20 changes: 15 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ plugins {
id("idea")
}

group = "org.jetbrains.compose.intellij.platform"
version = "1.0-SNAPSHOT"
group = "com.wilinz.globalization"
version = "1.0.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -42,6 +42,16 @@ intellij {
)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
tasks{
withType<JavaCompile> {
sourceCompatibility = "9"
targetCompatibility = "11"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
patchPluginXml {
sinceBuild.set("172")
untilBuild.set("252")
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/com/wilinz/globalization/translator/Debug.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wilinz.globalization.translator

const val isDebug = false

fun printlnDebug(message: Any?) {
if (isDebug) println(message)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wilinz.globalization.translator.network

import com.wilinz.globalization.translator.isDebug
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.time.Duration
Expand All @@ -8,7 +9,7 @@ object OkHttp {
private val logging = HttpLoggingInterceptor()

init {
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
logging.setLevel(if (isDebug) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE);
}

val client = OkHttpClient.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wilinz.globalization.translator.translator.engine

import com.google.gson.JsonParser
import com.wilinz.globalization.translator.network.OkHttp
import com.wilinz.globalization.translator.printlnDebug
import com.wilinz.globalization.translator.util.converseResult
import okhttp3.Call
import okhttp3.FormBody
Expand Down Expand Up @@ -41,9 +42,11 @@ class GoogleTranslator : Translator {
try {
val response = call.execute()
response.body?.string()?.let {
return JsonParser.parseString(it).asJsonArray.map { element ->
val result = JsonParser.parseString(it).asJsonArray.map { element ->
element.asString.converseResult()
}
printlnDebug(result)
return result
}
} finally {
callList.remove(call)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.openapi.vfs.VirtualFile

private val isStringsFileRegex = Regex("^strings.xml$|^plurals.xml$|^arrays.xml$")
private val converseResultRegex = Regex("<b>(.*?)</b>")
private val converseResultRegex1 = Regex("<i>.*?</b>")
private val converseResultRegex1 = Regex("^<i>.*</b>$")
internal fun VirtualFile.isStringsXmlFile(): Boolean {
val parent = this.parent ?: return false
if (!parent.name.matches(Regex("^values.*$"))) return false
Expand Down Expand Up @@ -46,7 +46,7 @@ fun String.unescapeHTML(): String {

internal fun String.converseResult(): String {
if (converseResultRegex1.matches(this)) {
return converseResultRegex.findAll(this).joinToString(". ")
return converseResultRegex.findAll(this).mapNotNull { it.groups.getOrNull(1)?.value }.joinToString(" ")
}
return this
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.compose.intellij.platform</depends>
<depends>org.jetbrains.kotlin</depends>
<idea-version since-build="100"/>
<!-- <idea-version since-build="100"/>-->

<actions>
<!-- Add your actions here -->
Expand Down
9 changes: 2 additions & 7 deletions src/test/kotlin/com/wilinz/globalization/translator/Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.dom4j.io.SAXReader
import org.dom4j.io.XMLWriter
import org.junit.Test
import java.io.File
import java.io.StringReader

class Test {

Expand All @@ -24,7 +25,7 @@ class Test {
fun testAndroidXmlTranslator() {
val saxReader = SAXReader()
val document =
saxReader.read(File(""))//Enter your strings.xml file path
saxReader.read(StringReader("<r><string name=\"crash_feedback\">将会自动提交错误信息。您也可以手动复制调试信息提交给开发者(*^▽^*)或者点击\\\"退出\\\"退出程序o(╥﹏╥)o</string></r>"))
AndroidXmlTranslator.translate(
translator = GoogleTranslator(),
oldDocument = document,
Expand Down Expand Up @@ -52,10 +53,4 @@ class Test {
)
}

@Test
fun test1() {
val result = message("translate_file",'a')
println(result)
}

}

0 comments on commit fc45bd0

Please sign in to comment.