Skip to content

Commit

Permalink
Topbar localization follow-ups (#2583)
Browse files Browse the repository at this point in the history
### What's done:
 * Finished topbar localization
  • Loading branch information
sanyavertolet authored Sep 13, 2023
1 parent 41df0be commit d49f860
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.saveourtool.save.frontend.components.topbar
import com.saveourtool.save.frontend.components.basic.avatarRenderer
import com.saveourtool.save.frontend.components.modal.logoutModal
import com.saveourtool.save.frontend.externals.fontawesome.*
import com.saveourtool.save.frontend.externals.i18next.useTranslation
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.validation.FrontendRoutes
Expand All @@ -23,11 +24,6 @@ import react.router.useNavigate
import web.cssom.ClassName
import web.cssom.rem

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.isActive

@Suppress("MAGIC_NUMBER")
val logoSize: CSSProperties = jso {
height = 2.5.rem
Expand All @@ -44,17 +40,11 @@ val logoSize: CSSProperties = jso {
"LOCAL_VARIABLE_EARLY_DECLARATION"
)
val topBarUserField: FC<TopBarUserFieldProps> = FC { props ->
val scope = CoroutineScope(Dispatchers.Default)
val (t) = useTranslation("topbar")
val navigate = useNavigate()
var isLogoutModalOpen by useState(false)
var isAriaExpanded by useState(false)
useEffect {
cleanup {
if (scope.isActive) {
scope.cancel()
}
}
}

ul {
className = ClassName("navbar-nav ml-auto")
div {
Expand Down Expand Up @@ -85,9 +75,9 @@ val topBarUserField: FC<TopBarUserFieldProps> = FC { props ->
className = ClassName("text-gray-400 text-justify")
props.userInfo?.let {
if (props.userInfo.isSuperAdmin()) {
+"Super user"
+"Super user".t()
} else {
+"User settings"
+"User settings".t()
}
}
}
Expand All @@ -109,31 +99,31 @@ val topBarUserField: FC<TopBarUserFieldProps> = FC { props ->
className = ClassName("dropdown-menu dropdown-menu-right shadow animated--grow-in${if (isAriaExpanded) " show" else ""}")
ariaLabelledBy = "userDropdown"
props.userInfo?.name?.let { name ->
dropdownEntry(faUser, "Profile") { attrs ->
dropdownEntry(faUser, "Profile".t()) { attrs ->
attrs.onClick = {
navigate(to = "/${FrontendRoutes.PROFILE}/$name")
}
}
dropdownEntry(faCog, "Settings") { attrs ->
dropdownEntry(faCog, "Settings".t()) { attrs ->
attrs.onClick = {
navigate(to = "/${FrontendRoutes.SETTINGS_PROFILE}")
}
}
dropdownEntry(
faCity,
"Manage organizations"
"Manage organizations".t()
) { attrs ->
attrs.onClick = {
navigate(to = "/${FrontendRoutes.SETTINGS_ORGANIZATIONS}")
}
}
dropdownEntry(faSignOutAlt, "Log out") { attrs ->
dropdownEntry(faSignOutAlt, "Log out".t()) { attrs ->
attrs.onClick = {
isLogoutModalOpen = true
}
}
} ?: run {
dropdownEntry(faSignInAlt, "Log in") { attrs ->
dropdownEntry(faSignInAlt, "Log in".t()) { attrs ->
attrs.onClick = {
navigate(to = "/")
}
Expand Down
9 changes: 8 additions & 1 deletion save-frontend/src/main/resources/locales/en/topbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
"Vulnerabilities": "Vulnerabilities",
"Top Rating": "Top Rating",
"SAVE Projects list": "SAVE Projects list",
"Vulnerabilities list": "Vulnerabilities list"
"Vulnerabilities list": "Vulnerabilities list",
"Super user": "Super user",
"User settings": "User settings",
"Profile": "Profile",
"Settings": "Settings",
"Manage organizations": "Manage organizations",
"Log out": "Log out",
"Log in": "Log in"
}
9 changes: 8 additions & 1 deletion save-frontend/src/main/resources/locales/ru/topbar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
"Vulnerabilities": "Уязвимости",
"Top Rating": "Рейтинг",
"SAVE Projects list": "SAVE-проекты",
"Vulnerabilities list": "Список уязвимостей"
"Vulnerabilities list": "Список уязвимостей",
"Super user": "Администратор",
"User settings": "Настройки",
"Profile": "Профиль",
"Settings": "Настройки",
"Manage organizations": "Управлять организациями",
"Log out": "Выйти из аккаунта",
"Log in": "Войти в аккаунт"
}

0 comments on commit d49f860

Please sign in to comment.