Skip to content

Commit f215b1d

Browse files
authored
feat: Add AI-powered translation support for API documentation (#1207)
1 parent 5c8cf2f commit f215b1d

File tree

19 files changed

+882
-25
lines changed

19 files changed

+882
-25
lines changed

common-api/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ dependencies {
2222
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
2323
compileOnly("org.apache.httpcomponents:httpclient:4.5.10")
2424

25+
compileOnly("com.google.code.gson:gson:2.8.6")
26+
2527
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime
2628
testImplementation("org.apache.httpcomponents:httpmime:4.5.10")
2729

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.itangcent.common.constant
2+
3+
/**
4+
* Enum representing supported languages for translation
5+
* @property code The language ISO code (e.g., "en", "zh")
6+
* @property displayName The human-readable language name (e.g., "English", "Chinese")
7+
*/
8+
enum class Language(val code: String, val displayName: String) {
9+
ENGLISH("en", "English"),
10+
CHINESE("zh", "Chinese"),
11+
SPANISH("es", "Spanish"),
12+
FRENCH("fr", "French"),
13+
GERMAN("de", "German"),
14+
JAPANESE("ja", "Japanese"),
15+
KOREAN("ko", "Korean"),
16+
RUSSIAN("ru", "Russian"),
17+
PORTUGUESE("pt", "Portuguese"),
18+
ITALIAN("it", "Italian"),
19+
DUTCH("nl", "Dutch"),
20+
ARABIC("ar", "Arabic"),
21+
HINDI("hi", "Hindi"),
22+
TURKISH("tr", "Turkish"),
23+
VIETNAMESE("vi", "Vietnamese");
24+
25+
companion object {
26+
/**
27+
* Find a Language by its code
28+
* @param code The language code to search for
29+
* @return The Language enum value or null if not found
30+
*/
31+
fun fromCode(code: String?): Language? {
32+
return entries.find { it.code == code }
33+
}
34+
35+
/**
36+
* Get the language name from its code
37+
* @param code The language code
38+
* @return The language name or the original code if not found
39+
*/
40+
fun getNameFromCode(code: String): String {
41+
return fromCode(code)?.displayName ?: code
42+
}
43+
44+
/**
45+
* Get the default language (English)
46+
*/
47+
fun getDefault(): Language = ENGLISH
48+
}
49+
}

common-api/src/main/kotlin/com/itangcent/common/model/Doc.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.itangcent.common.model
22

33
import com.itangcent.common.utils.SimpleExtensible
4+
import com.google.gson.annotations.Expose
45
import java.io.Serializable
56

67
/**
@@ -11,6 +12,8 @@ open class Doc : SimpleExtensible(), Serializable {
1112
/**
1213
* The element associated the origin code.
1314
*/
15+
@Transient
16+
@Expose(serialize = false, deserialize = false)
1417
var resource: Any? = null
1518

1619
/**

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/PostmanExportAction.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class PostmanExportAction : ApiExportAction("Export Postman") {
3030
builder.bindInstance(ExportChannel::class, ExportChannel.of("postman"))
3131
builder.bindInstance(ExportDoc::class, ExportDoc.of("request"))
3232

33-
builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
34-
3533
builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() }
3634

3735
builder.bindInstance("file.save.default", "postman.json")

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/YapiExportAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class YapiExportAction : ApiExportAction("Export Yapi") {
2929
builder.bindInstance(ExportChannel::class, ExportChannel.of("yapi"))
3030
builder.bindInstance(ExportDoc::class, ExportDoc.of("request", "methodDoc"))
3131

32-
builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
3332
builder.bind(MethodDocBuilderListener::class) { it.with(CompositeMethodDocBuilderListener::class).singleton() }
3433

3534
builder.bind(MethodFilter::class) { it.with(ConfigurableMethodFilter::class).singleton() }

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/RequestBuilderListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.itangcent.idea.plugin.api.export.core
33
import com.google.inject.ImplementedBy
44
import com.itangcent.common.model.*
55

6-
@ImplementedBy(DefaultRequestBuilderListener::class)
6+
@ImplementedBy(CompositeRequestBuilderListener::class)
77
interface RequestBuilderListener {
88

99
fun setName(

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/suv/SuvApiExporter.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ open class SuvApiExporter {
344344
builder.bindInstance(ExportChannel::class, ExportChannel.of("postman"))
345345
builder.bindInstance(ExportDoc::class, ExportDoc.of("request"))
346346

347-
builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
348-
349347
builder.bindInstance("file.save.default", "postman.json")
350348
builder.bindInstance("file.save.last.location.key", "com.itangcent.postman.export.path")
351349

@@ -383,7 +381,6 @@ open class SuvApiExporter {
383381
builder.bindInstance(ExportChannel::class, ExportChannel.of("yapi"))
384382
builder.bindInstance(ExportDoc::class, ExportDoc.of("request", "methodDoc"))
385383

386-
builder.bind(RequestBuilderListener::class) { it.with(CompositeRequestBuilderListener::class).singleton() }
387384
builder.bind(MethodDocBuilderListener::class) {
388385
it.with(CompositeMethodDocBuilderListener::class).singleton()
389386
}

0 commit comments

Comments
 (0)