Skip to content

Commit 9265906

Browse files
try fix #2 loading kubejs lang
1 parent 7cdd2a9 commit 9265906

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/kotlin/icu/takeneko/appwebterminal/util/KubejsI18nSupport.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package icu.takeneko.appwebterminal.util
22

33
import com.google.common.collect.HashBasedTable
4+
import com.mojang.logging.LogUtils
45
import kotlinx.serialization.json.Json
6+
import kotlinx.serialization.json.JsonDecoder
57
import kotlin.io.path.Path
68
import kotlin.io.path.div
79
import kotlin.io.path.exists
@@ -12,6 +14,7 @@ import kotlin.io.path.nameWithoutExtension
1214
object KubejsI18nSupport {
1315
private const val DEFAULT_LANGUAGE = "en_us"
1416
private val languages = HashBasedTable.create<String, String, String>()
17+
private val logger = LogUtils.getLogger()
1518

1619
private val Json = Json {
1720
ignoreUnknownKeys = true
@@ -23,11 +26,15 @@ object KubejsI18nSupport {
2326
basePath.listDirectoryEntries().forEach {
2427
val langDir = it / "lang"
2528
if (!langDir.exists()) return@init
26-
langDir.listDirectoryEntries().forEach { langFile ->
29+
langDir.listDirectoryEntries("*.json").forEach { langFile ->
2730
val langName = langFile.nameWithoutExtension
28-
val map = Json.decodeFromString<Map<String, String>>(langFile.toFile().readText(Charsets.UTF_8))
29-
map.forEach { k, v ->
30-
languages.put(langName, k, v)
31+
try {
32+
val map = Json.decodeFromString<Map<String, String>>(langFile.toFile().readText(Charsets.UTF_8))
33+
map.forEach { k, v ->
34+
languages.put(langName, k, v)
35+
}
36+
} catch (e: Exception) {
37+
logger.error("Error while reading $langFile", e)
3138
}
3239
}
3340
}

0 commit comments

Comments
 (0)