From c137b8afcdcb6eb633e746ec89bdd82e8734ee66 Mon Sep 17 00:00:00 2001 From: Al Murad Uzzaman Date: Thu, 16 May 2024 17:11:25 +0600 Subject: [PATCH] config ln array changed --- src/config/config.json | 6 +- src/i18n/ar.json | 59 +++++------------ src/i18n/en.json | 59 +++++------------ src/i18n/fr.json | 59 +++++------------ src/i18n/ui.ts | 63 ------------------ src/layouts/components/BlogCard.astro | 15 +++-- src/layouts/components/Breadcrumbs.astro | 12 ++-- src/layouts/helpers/LanguageSwitcher.tsx | 17 ++--- src/layouts/partials/Header.astro | 22 ++----- src/lib/contentParser.astro | 34 ++++------ src/lib/taxonomyParser.astro | 6 +- src/lib/utils/i18nUtils.ts | 64 +++++++------------ src/pages/404.astro | 22 ++++--- src/pages/[...lang]/[regular].astro | 6 +- src/pages/[...lang]/about.astro | 13 ++-- src/pages/[...lang]/authors/[single].astro | 13 ++-- src/pages/[...lang]/authors/index.astro | 5 +- src/pages/[...lang]/blog/[single].astro | 12 ++-- src/pages/[...lang]/blog/index.astro | 4 +- src/pages/[...lang]/blog/page/[slug].astro | 18 +++--- .../[...lang]/categories/[category].astro | 6 +- src/pages/[...lang]/categories/index.astro | 7 +- src/pages/[...lang]/contact.astro | 27 +++++--- src/pages/[...lang]/index.astro | 13 ++-- 24 files changed, 200 insertions(+), 362 deletions(-) delete mode 100644 src/i18n/ui.ts diff --git a/src/config/config.json b/src/config/config.json index 0e5aab5..396aa11 100755 --- a/src/config/config.json +++ b/src/config/config.json @@ -13,8 +13,7 @@ }, "language": { - "defaultLang": "en", - "supported": ["", "en", "fr", "ar"] + "defaultLang": "en" }, "settings": { @@ -24,7 +23,8 @@ "default_theme": "system", "pagination": 2, "summary_length": 200, - "blog_folder": "blog" + "blog_folder": "blog", + "default_language": "en" }, "params": { diff --git a/src/i18n/ar.json b/src/i18n/ar.json index 0d559d3..e49a06a 100644 --- a/src/i18n/ar.json +++ b/src/i18n/ar.json @@ -1,42 +1,17 @@ -[ - { - "id": "get_started", - "translation": "البدء" - }, - { - "id": "read_more", - "translation": "Read More" - }, - { - "id": "full_name", - "translation": "الاسم الكامل" - }, - { - "id": "working_mail", - "translation": "بريد العمل" - }, - { - "id": "anything_else", - "translation": "أي شيء آخر؟" - }, - { - "id": "contact_message_placeholder", - "translation": "الرسالة تذهب هنا..." - }, - { - "id": "submit", - "translation": "يُقدِّم" - }, - { - "id": "page_not_found", - "translation": "الصفحة غير موجودة" - }, - { - "id": "page_not_found_content", - "translation": "ربما تمت إزالة الصفحة التي تبحث عنها، أو تم تغيير اسمها، أو أنها غير متاحة مؤقتًا." - }, - { - "id": "back_to_home", - "translation": "العودة إلى المنزل" - } -] \ No newline at end of file +{ + "full_name": "الاسم الكامل", + "full_name_placeholder": "أدخل اسمك الكامل", + "mail": "البريد الإلكتروني العملي", + "mail_placeholder": "john.doe@email.com", + "message": "هل هناك شيء آخر؟", + "message_placeholder": "رسالتك هنا...", + "submit": "إرسال", + "read_more": "اقرأ المزيد", + "page_not_found": "الصفحة غير موجودة", + "working_mail": "البريد الإلكتروني العملي", + "anything_else": "هل هناك شيء آخر؟", + "contact_message_placeholder": "رسالتك هنا...", + "page_not_found_content": "قد تمت إزالة الصفحة التي تبحث عنها، أو تغيير اسمها، أو أصبحت غير متوفرة مؤقتًا.", + "back_to_home": "العودة إلى الصفحة الرئيسية", + "get_started": "البدئة" +} diff --git a/src/i18n/en.json b/src/i18n/en.json index 6e16ff3..cad49ee 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1,42 +1,17 @@ -[ - { - "id": "get_started", - "translation": "Get Started" - }, - { - "id": "read_more", - "translation": "Read More" - }, - { - "id": "full_name", - "translation": "Full Name" - }, - { - "id": "working_mail", - "translation": "Working Mail" - }, - { - "id": "anything_else", - "translation": "Anything else?" - }, - { - "id": "contact_message_placeholder", - "translation": "Message goes here..." - }, - { - "id": "submit", - "translation": "Submit" - }, - { - "id": "page_not_found", - "translation": "Page Not Found" - }, - { - "id": "page_not_found_content", - "translation": "The page you are looking for might have been removed, had its name changed, or is temporarily unavailable." - }, - { - "id": "back_to_home", - "translation": "Back to home" - } -] \ No newline at end of file +{ + "full_name": "Full Name", + "full_name_placeholder": "Enter your full name", + "mail": "Work Email", + "mail_placeholder": "john.doe@email.com", + "message": "Anything else?", + "message_placeholder": "Your message here...", + "submit": "Submit", + "read_more": "Read More", + "page_not_found": "Page Not Found", + "working_mail": "Work Email", + "anything_else": "Anything else?", + "contact_message_placeholder": "Your message here...", + "page_not_found_content": "The page you are looking for may have been removed, renamed, or is temporarily unavailable.", + "back_to_home": "Back to Home", + "get_started": "Get Started" +} diff --git a/src/i18n/fr.json b/src/i18n/fr.json index b1ffa15..91948b0 100644 --- a/src/i18n/fr.json +++ b/src/i18n/fr.json @@ -1,42 +1,17 @@ -[ - { - "id": "get_started", - "translation": "Commencer" - }, - { - "id": "read_more", - "translation": "Read More" - }, - { - "id": "full_name", - "translation": "Nom et prénom" - }, - { - "id": "working_mail", - "translation": "Courrier de travail" - }, - { - "id": "anything_else", - "translation": "Rien d'autre?" - }, - { - "id": "contact_message_placeholder", - "translation": "Le message va ici..." - }, - { - "id": "submit", - "translation": "Soumettre" - }, - { - "id": "page_not_found", - "translation": "Page non trouvée" - }, - { - "id": "page_not_found_content", - "translation": "La page que vous recherchez a peut-être été supprimée, son nom a changé ou est temporairement indisponible." - }, - { - "id": "back_to_home", - "translation": "De retour à la maison" - } -] \ No newline at end of file +{ + "full_name": "Nom complet", + "full_name_placeholder": "Entrez votre nom complet", + "mail": "E-mail de travail", + "mail_placeholder": "john.doe@email.com", + "message": "Autre chose?", + "message_placeholder": "Votre message ici...", + "submit": "Soumettre", + "read_more": "Lire la suite", + "page_not_found": "Page non trouvée", + "working_mail": "Courrier de travail", + "anything_else": "Autre chose ?", + "contact_message_placeholder": "Votre message ici...", + "page_not_found_content": "La page que vous recherchez a peut-être été supprimée, changée de nom ou temporairement inaccessible.", + "back_to_home": "Retour à l'accueil", + "get_started": "Commencez à utiliser" +} diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts deleted file mode 100644 index 23ac00a..0000000 --- a/src/i18n/ui.ts +++ /dev/null @@ -1,63 +0,0 @@ -import enDataJSON from './en.json'; -import frDataJSON from './fr.json'; -import arDataJSON from './ar.json'; - - -interface TranslationItem { - id: string; - translation: string; -} - -export function convertJsonToUiObject(jsonData: TranslationItem[], language: string): Record> { - const ui: Record> = {}; - ui[language] = {}; - - for (const item of jsonData) { - ui[language][item.id] = item.translation; - } - - return ui; -} - - -export const ui = { - ...convertJsonToUiObject(enDataJSON, 'en'), - ...convertJsonToUiObject(frDataJSON, 'fr'), - ...convertJsonToUiObject(arDataJSON, 'ar') -} as const; - - -// import { readdirSync } from 'fs'; -// import path from 'path'; -// import { fileURLToPath } from 'url'; - -// interface TranslationItem { -// id: string; -// translation: string; -// } - -// function convertJsonToUiObject(jsonData: TranslationItem[]): Record { -// const ui: Record = {}; - -// for (const item of jsonData) { -// ui[item.id] = item.translation; -// } - -// return ui; -// } - -// const __filename = fileURLToPath(import.meta.url); -// const i18nFolderPath = path.join(path.dirname(__filename)); -// const ui: Record> = {}; - -// readdirSync(i18nFolderPath).forEach((file) => { -// if (file.endsWith('.json')) { -// const language = file.split('.')[0]; -// import(path.join(i18nFolderPath, file)).then((module) => { -// const jsonData: TranslationItem[] = module.default; -// ui[language] = convertJsonToUiObject(jsonData); -// }); -// } -// }); - -// export { ui }; \ No newline at end of file diff --git a/src/layouts/components/BlogCard.astro b/src/layouts/components/BlogCard.astro index 015b2cb..606aca0 100644 --- a/src/layouts/components/BlogCard.astro +++ b/src/layouts/components/BlogCard.astro @@ -1,20 +1,23 @@ --- import config from "@/config/config.json"; import dateFormat from "@/lib/utils/dateFormat"; +import { getLangFromUrl, getTranslations } from "@/lib/utils/i18nUtils"; import { humanize, plainify, slugify } from "@/lib/utils/textConverter"; +import type { ContentEntryMap } from "astro:content"; import { FaRegFolder, FaRegUserCircle } from "react-icons/fa"; import ImageMod from "./ImageMod.astro"; -import { getLangFromUrl } from "@/lib/utils/i18nUtils"; const { summary_length, blog_folder, }: { summary_length: number; blog_folder: string } = config.settings; +const { defaultLang } = config.language; const { data } = Astro.props; const { title, image, date, author, categories } = data.data; const lang = getLangFromUrl(Astro.url); const path = Astro.url.pathname; +const { read_more } = await getTranslations(lang as keyof ContentEntryMap); ---
@@ -33,8 +36,8 @@ const path = Astro.url.pathname;

{title} @@ -63,9 +66,9 @@ const path = Astro.url.pathname; - read more + {read_more}

diff --git a/src/layouts/components/Breadcrumbs.astro b/src/layouts/components/Breadcrumbs.astro index fb029b1..38a9f27 100644 --- a/src/layouts/components/Breadcrumbs.astro +++ b/src/layouts/components/Breadcrumbs.astro @@ -1,15 +1,13 @@ --- +import { supportedLang } from "@/lib/utils/i18nUtils"; import { humanize } from "@/lib/utils/textConverter"; -import config from "@/config/config.json"; - -const { supported } = config.language; const { className }: { className?: string } = Astro.props; const paths = Astro.url.pathname.split("/").filter((x) => x); let lang = ""; -if (supported.includes(paths[0])) { +if (supportedLang.includes(paths[0])) { lang = paths.shift()!; } @@ -17,7 +15,10 @@ let parts = [ { label: "Home", href: `/${lang}`, - "aria-label": Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/` ? "page" : undefined, + "aria-label": + Astro.url.pathname === `/${lang}` || Astro.url.pathname === `/${lang}/` + ? "page" + : undefined, }, ]; @@ -30,7 +31,6 @@ paths.forEach((label: string, i: number) => { "aria-label": Astro.url.pathname === href ? "page" : undefined, }); }); - ---