-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What's done: * Added language selector * Added several languages to be supported * Fixed invoke operator in Translation class * Added language selector to TopBar
- Loading branch information
1 parent
1ac3bd9
commit edfd998
Showing
6 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/frontend/PlatformLanguages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.saveourtool.save.frontend | ||
|
||
/** | ||
* Enum that contains all supported saveourtool languages | ||
* | ||
* @property code language code | ||
* @property value language name | ||
* @property label language label | ||
*/ | ||
enum class PlatformLanguages(val code: String, val value: String, val label: String) { | ||
/** | ||
* Chinese | ||
*/ | ||
CN("cn", "Chinese", "中文"), | ||
|
||
/** | ||
* English | ||
*/ | ||
EN("en", "English", "EN"), | ||
|
||
/** | ||
* Russian | ||
*/ | ||
RU("ru", "Russian", "РУ"), | ||
; | ||
companion object { | ||
/** | ||
* Default platform language | ||
*/ | ||
val defaultLanguage = EN | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/LanguageSelector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@file:Suppress("HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE") | ||
|
||
package com.saveourtool.save.frontend.components.basic | ||
|
||
import com.saveourtool.save.frontend.PlatformLanguages | ||
import com.saveourtool.save.frontend.externals.i18next.useTranslation | ||
import js.core.jso | ||
import react.FC | ||
import react.VFC | ||
import react.dom.aria.AriaHasPopup | ||
import react.dom.aria.ariaExpanded | ||
import react.dom.aria.ariaHasPopup | ||
import react.dom.aria.ariaLabelledBy | ||
import react.dom.html.ReactHTML.a | ||
import react.dom.html.ReactHTML.div | ||
import react.dom.html.ReactHTML.span | ||
import react.useEffect | ||
import react.useState | ||
import web.cssom.ClassName | ||
import web.cssom.Cursor | ||
|
||
private const val LANG_DROPDOWN_ID = "lang-dropdown" | ||
|
||
/** | ||
* A [FC] that is responsible for language selection | ||
*/ | ||
val languageSelector: VFC = FC { | ||
val (_, i18n) = useTranslation() | ||
val (language, setSelectedLanguage) = useState(PlatformLanguages.defaultLanguage) | ||
useEffect(language) { i18n.changeLanguage(language.code) } | ||
|
||
div { | ||
className = ClassName("dropdown") | ||
a { | ||
className = ClassName("dropdown-toggle") | ||
id = LANG_DROPDOWN_ID | ||
asDynamic()["data-toggle"] = "dropdown" | ||
ariaHasPopup = true.unsafeCast<AriaHasPopup>() | ||
ariaExpanded = false | ||
style = jso { cursor = "pointer".unsafeCast<Cursor>() } | ||
span { +language.label } | ||
} | ||
|
||
div { | ||
className = ClassName("dropdown-menu") | ||
ariaLabelledBy = LANG_DROPDOWN_ID | ||
PlatformLanguages.values().map { language -> | ||
a { | ||
className = ClassName("dropdown-item") | ||
onClick = { setSelectedLanguage(language) } | ||
span { +language.label } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters