Skip to content

Commit 70f4c26

Browse files
committed
Refactor locale resource loading logic
Read the locale strings as UTF-8
1 parent 26c53c9 commit 70f4c26

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

app/src/processing/app/ui/theme/Locale.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import processing.app.Messages
77
import processing.app.watchFile
88
import processing.utils.Settings
99
import java.io.File
10-
import java.io.InputStream
1110
import java.util.*
1211

1312
/**
@@ -26,21 +25,18 @@ import java.util.*
2625
class Locale(language: String = "", val setLocale: ((java.util.Locale) -> Unit)? = null) : Properties() {
2726
var locale: java.util.Locale = java.util.Locale.getDefault()
2827

28+
fun loadResource(resourcePath: String) {
29+
val stream = ClassLoader.getSystemResourceAsStream(resourcePath) ?: return
30+
load(stream.reader(Charsets.UTF_8))
31+
}
32+
2933
init {
30-
val locale = java.util.Locale.getDefault()
31-
load(ClassLoader.getSystemResourceAsStream("languages/PDE.properties"))
32-
load(
33-
ClassLoader.getSystemResourceAsStream("languages/PDE_${locale.language}.properties")
34-
?: InputStream.nullInputStream()
35-
)
36-
load(
37-
ClassLoader.getSystemResourceAsStream("languages/PDE_${locale.toLanguageTag()}.properties")
38-
?: InputStream.nullInputStream()
39-
)
40-
load(
41-
ClassLoader.getSystemResourceAsStream("languages/PDE_${language}.properties")
42-
?: InputStream.nullInputStream()
43-
)
34+
loadResource("languages/PDE.properties")
35+
loadResource("languages/PDE_${locale.language}.properties")
36+
loadResource("languages/PDE_${locale.toLanguageTag()}.properties")
37+
if (language.isNotEmpty()) {
38+
loadResource("languages/PDE_${language}.properties")
39+
}
4440
}
4541

4642
@Deprecated("Use get instead", ReplaceWith("get(key)"))

0 commit comments

Comments
 (0)