From 56283ecd50cb69bb8506df2ca00c05d1e1cea785 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 29 Apr 2024 01:33:33 +0300 Subject: [PATCH] menu translations and ability to add new translations using the base translation --- components/sidebar.tsx | 11 ++++- components/sidemenuData.js | 7 +++ content/i18n/bg.json | 26 ++++++++++- content/i18n/bg.modified.json | 34 ++++++++++++++ content/i18n/en.json | 4 +- content/i18n/en.modified.json | 15 +++++++ pages/cart/translations/index.tsx | 74 ++++++++++++++++++++----------- 7 files changed, 141 insertions(+), 30 deletions(-) create mode 100644 content/i18n/bg.modified.json create mode 100644 content/i18n/en.modified.json diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 1f562d8..d13e202 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -6,10 +6,13 @@ import sidemenu, { footerMenu } from './sidemenuData.js'; // Move sidemenu data import axiosInstance from "src/axiosSecure"; import common from "src/helpers/common"; import LanguageSwitcher from "./languageSwitcher"; +import { useTranslations } from 'next-intl'; //get package version from package.json const packageVersion = require('../package.json').version; function SidebarMenuItem({ item, session, isSubmenu }) { + // const tMenu = useTranslations('menu'); + const t = useTranslations('common'); const router = useRouter(); const isActive = router.pathname.includes(item.url); @@ -92,6 +95,7 @@ export default function Sidebar({ isSidebarOpen, toggleSidebar }) { const { data: session, status } = useSession(); const sidebarWidth = 226; // Simplify by using a constant const sidebarRef = useRef(null); + const t = useTranslations('menu'); //const [locations, setLocations] = useState([]); @@ -137,6 +141,7 @@ export default function Sidebar({ isSidebarOpen, toggleSidebar }) {
diff --git a/components/sidemenuData.js b/components/sidemenuData.js index b845493..e884535 100644 --- a/components/sidemenuData.js +++ b/components/sidemenuData.js @@ -1,6 +1,7 @@ import { UserRole } from "@prisma/client"; + const sidemenu = [ { id: "dashboard", @@ -118,6 +119,12 @@ const sidemenu = [ url: "/cart/reports/coverMe", roles: [UserRole.ADMIN, UserRole.POWERUSER], }, + { + id: "translations", + text: "Преводи", + url: "/cart/translations", + roles: [UserRole.ADMIN, UserRole.POWERUSER], + }, ] }, diff --git a/content/i18n/bg.json b/content/i18n/bg.json index 84dfa1c..1283bc1 100644 --- a/content/i18n/bg.json +++ b/content/i18n/bg.json @@ -5,6 +5,30 @@ "changeTo": "Смени на", "BG": "Български", "EN": "Английски", - "RU": "Руски" + "RU": "Руски", + "login": "Вход", + "logout": "Изход" + }, + "menu": { + "dashboard": "Възможности", + "shedule": "График", + "myshedule": "Моя График", + "locations": "Местоположения", + "cart-report": "Отчет", + "cart-experience": "Случки", + "guidelines": "Напътствия", + "permits": "Разрешителни", + "contactAll": "Участници", + "feedback": "Отзиви", + "contactUs": "За връзка", + "admin": "Админ", + "cart-places": "Места", + "cart-publishers": "Вестители", + "cart-events": "План", + "cart-calendar": "Календар", + "cart-reports": "Отчети", + "statistics": "Статистика", + "coverMeLogs": "Замествания", + "translations": "Преводи" } } \ No newline at end of file diff --git a/content/i18n/bg.modified.json b/content/i18n/bg.modified.json new file mode 100644 index 0000000..34515c1 --- /dev/null +++ b/content/i18n/bg.modified.json @@ -0,0 +1,34 @@ +{ + "common": { + "greeting": "Здравей", + "farewell": "Довиждане", + "changeTo": "", + "BG": "Български", + "EN": "Английски", + "RU": "Руски", + "login": "Вход", + "logout": "Изход" + }, + "menu": { + "dashboard": "Възможности", + "shedule": "График", + "myshedule": "Моя График", + "locations": "Местоположения", + "cart-report": "Отчет", + "cart-experience": "Случки", + "guidelines": "Напътствия", + "permits": "Разрешителни", + "contactAll": "Участници", + "feedback": "Отзиви", + "contactUs": "За връзка", + "admin": "Админ", + "cart-places": "Места", + "cart-publishers": "Вестители", + "cart-events": "План", + "cart-calendar": "Календар", + "cart-reports": "Отчети", + "statistics": "Статистика", + "coverMeLogs": "Замествания", + "translations": "Преводи" + } +} \ No newline at end of file diff --git a/content/i18n/en.json b/content/i18n/en.json index 59f2c2e..626bb9e 100644 --- a/content/i18n/en.json +++ b/content/i18n/en.json @@ -5,6 +5,8 @@ "changeTo": "Change to", "BG": "Bulgarian", "EN": "English", - "RU": "Russian" + "RU": "Russian", + "login": "login", + "logout": "logout" } } \ No newline at end of file diff --git a/content/i18n/en.modified.json b/content/i18n/en.modified.json new file mode 100644 index 0000000..4a17b81 --- /dev/null +++ b/content/i18n/en.modified.json @@ -0,0 +1,15 @@ +{ + "common": { + "greeting": "Hello", + "farewell": "Goodbye", + "changeTo": "Change to", + "BG": "Bulgarian", + "EN": "English", + "RU": "Russian", + "login": "login", + "logout": "logout" + }, + "menu": { + "dashboard": "Dashboard" + } +} \ No newline at end of file diff --git a/pages/cart/translations/index.tsx b/pages/cart/translations/index.tsx index 782c4f7..dac44fe 100644 --- a/pages/cart/translations/index.tsx +++ b/pages/cart/translations/index.tsx @@ -35,34 +35,56 @@ const AdminTranslations = () => { return ( - -
-

Edit Translations

- - - - {Object.entries(translations).map(([key, value]) => ( - - - - - +
+

Edit Translations

+
+ +
-
{key}{baseTranslations[key]} - handleChange(key, e.target.value)} - style={{ width: '100%' }} - /> -
- + +
+
+ + + + + + + + + + {Object.entries(baseTranslations).map(([key, baseValue]) => ( + + + + + + ))} + +
KeyBase TranslationTranslation
{key}{baseValue} + handleChange(key, e.target.value)} + className="block w-full text-base px-2 py-1 border border-gray-300 focus:ring-blue-500 focus:border-blue-500 rounded" + /> +
+
+