Skip to content

Commit afdbaf6

Browse files
committed
feat: the languages menu now displays the name in the target language, related to #1170 and #1172
1 parent c4b44da commit afdbaf6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

fxgl-core/src/main/kotlin/com/almasb/fxgl/localization/Language.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@ package com.almasb.fxgl.localization
99
/**
1010
* @author Almas Baimagambetov (almaslvl@gmail.com)
1111
*/
12-
class Language(name: String) {
12+
class Language
13+
@JvmOverloads constructor(
14+
15+
/**
16+
* In English.
17+
*/
18+
name: String,
19+
20+
/**
21+
* In the target language.
22+
*/
23+
val nativeName: String = name) {
1324

1425
val name = name.uppercase()
1526

@@ -30,12 +41,12 @@ class Language(name: String) {
3041
@JvmField val ESTONIAN = Language("ESTONIAN")
3142
@JvmField val FILIPINO = Language("FILIPINO")
3243
@JvmField val FINNISH = Language("FINNISH")
33-
@JvmField val FRENCH = Language("FRENCH")
34-
@JvmField val GERMAN = Language("GERMAN")
44+
@JvmField val FRENCH = Language("FRENCH", "Français")
45+
@JvmField val GERMAN = Language("GERMAN", "Deutsch")
3546
@JvmField val GREEK = Language("GREEK")
3647
@JvmField val HEBREW = Language("HEBREW")
3748
@JvmField val HINDI = Language("HINDI")
38-
@JvmField val HUNGARIAN = Language("HUNGARIAN")
49+
@JvmField val HUNGARIAN = Language("HUNGARIAN", "Magyar")
3950
@JvmField val INDONESIAN = Language("INDONESIAN")
4051
@JvmField val ITALIAN = Language("ITALIAN")
4152
@JvmField val JAPANESE = Language("JAPANESE")
@@ -44,7 +55,7 @@ class Language(name: String) {
4455
@JvmField val NORWEGIAN = Language("NORWEGIAN")
4556
@JvmField val PORTUGUESE = Language("PORTUGUESE")
4657
@JvmField val ROMANIAN = Language("ROMANIAN")
47-
@JvmField val RUSSIAN = Language("RUSSIAN")
58+
@JvmField val RUSSIAN = Language("RUSSIAN", "Русский")
4859
@JvmField val SLOVAK = Language("SLOVAK")
4960
@JvmField val SPANISH = Language("SPANISH")
5061
@JvmField val SWEDISH = Language("SWEDISH")

fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/FXGLDefaultMenu.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.almasb.fxgl.input.InputModifier
2121
import com.almasb.fxgl.input.Trigger
2222
import com.almasb.fxgl.input.UserAction
2323
import com.almasb.fxgl.input.view.TriggerView
24+
import com.almasb.fxgl.localization.Language
2425
import com.almasb.fxgl.logging.Logger
2526
import com.almasb.fxgl.particle.ParticleEmitters
2627
import com.almasb.fxgl.particle.ParticleSystem
@@ -46,6 +47,7 @@ import javafx.scene.paint.*
4647
import javafx.scene.shape.Polygon
4748
import javafx.scene.shape.Rectangle
4849
import javafx.util.Duration
50+
import javafx.util.StringConverter
4951
import java.time.format.DateTimeFormatter
5052
import java.util.*
5153
import java.util.function.Consumer
@@ -661,6 +663,15 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
661663

662664
val languageBox = getUIFactoryService().newChoiceBox(FXCollections.observableArrayList(getSettings().supportedLanguages))
663665
languageBox.value = getSettings().language.value
666+
languageBox.converter = object : StringConverter<Language>() {
667+
override fun toString(`object`: Language): String {
668+
return `object`.nativeName
669+
}
670+
671+
override fun fromString(string: String): Language {
672+
return getSettings().supportedLanguages.find { it.nativeName == string } ?: Language.NONE
673+
}
674+
}
664675

665676
getSettings().language.bindBidirectional(languageBox.valueProperty())
666677

0 commit comments

Comments
 (0)