From d49f86059a67822900663a393757169ea0eb7fe9 Mon Sep 17 00:00:00 2001 From: Alexander Frolov Date: Wed, 13 Sep 2023 17:01:27 +0400 Subject: [PATCH] Topbar localization follow-ups (#2583) ### What's done: * Finished topbar localization --- .../components/topbar/TopBarUserField.kt | 30 +++++++------------ .../src/main/resources/locales/en/topbar.json | 9 +++++- .../src/main/resources/locales/ru/topbar.json | 9 +++++- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/topbar/TopBarUserField.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/topbar/TopBarUserField.kt index afb530aa2d..b6fa9b5bd9 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/topbar/TopBarUserField.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/topbar/TopBarUserField.kt @@ -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 @@ -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 @@ -44,17 +40,11 @@ val logoSize: CSSProperties = jso { "LOCAL_VARIABLE_EARLY_DECLARATION" ) val topBarUserField: FC = 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 { @@ -85,9 +75,9 @@ val topBarUserField: FC = 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() } } } @@ -109,31 +99,31 @@ val topBarUserField: FC = 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 = "/") } diff --git a/save-frontend/src/main/resources/locales/en/topbar.json b/save-frontend/src/main/resources/locales/en/topbar.json index 7a35d220b8..fc6dc18897 100644 --- a/save-frontend/src/main/resources/locales/en/topbar.json +++ b/save-frontend/src/main/resources/locales/en/topbar.json @@ -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" } \ No newline at end of file diff --git a/save-frontend/src/main/resources/locales/ru/topbar.json b/save-frontend/src/main/resources/locales/ru/topbar.json index b55dcb0019..0d97e1531d 100644 --- a/save-frontend/src/main/resources/locales/ru/topbar.json +++ b/save-frontend/src/main/resources/locales/ru/topbar.json @@ -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": "Войти в аккаунт" } \ No newline at end of file