From 51d7dacc22022a1faf6a6b9d70e078c1c53a1b9c Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Tue, 31 Dec 2024 01:31:00 +0100 Subject: [PATCH 1/2] feat: add script to prune unused keys from dictionary and update package.json --- packages/tooling/prune-dictionary.ts | 61 ++++++++++++++++++++++++++++ web/package.json | 1 + 2 files changed, 62 insertions(+) create mode 100644 packages/tooling/prune-dictionary.ts diff --git a/packages/tooling/prune-dictionary.ts b/packages/tooling/prune-dictionary.ts new file mode 100644 index 00000000..cffd3367 --- /dev/null +++ b/packages/tooling/prune-dictionary.ts @@ -0,0 +1,61 @@ +// check for unused keys in dictionary.ts and prefix them with "skip-" +// to manually remove them later after double checking + +import { readFileSync, writeFileSync, readdirSync, statSync } from "fs"; + +const dictionaryPath = "./src/components/locale/dictionary.ts"; +const dictionary = readFileSync(dictionaryPath, "utf-8"); + +const keysRegex = /\s\s"(.*)":/g; +const keys = Array.from(dictionary.matchAll(keysRegex)).map((match) => match[1]); +const filteredKeys = keys.filter((key) => !key.startsWith("skip-")); +const keysRecord = filteredKeys.reduce>((acc, key) => { + acc[key] = null; + return acc; +}, {}); + +const srcPath = "./src"; +const exts = [".ts", ".tsx", ".js", ".jsx"]; +const ignoreExts = ["dictionary.ts"]; + +const walk = (dir: string) => { + const files = readdirSync(dir); + for (const file of files) { + const path = `${dir}/${file}`; + if (statSync(path).isDirectory()) { + walk(path); + } else { + if (!exts.some((ext) => path.endsWith(ext))) continue; + if (ignoreExts.some((ext) => path.endsWith(ext))) continue; + const content = readFileSync(path, "utf-8"); + const foundKeys = []; + for (const key in keysRecord) { + if (content.includes(key)) { + console.log(`Found key: ${key} in ${path}`); + + foundKeys.push(key); + } + } + foundKeys.forEach((key) => { + delete keysRecord[key]; + }); + } + } +}; + +walk(srcPath); + +const unusedKeys = Object.keys(keysRecord); +console.log(`Found ${unusedKeys.length} unused keys`); + +// prefix unused keys with "skip-" in dictionary variable +const newDictionary = dictionary.replace(keysRegex, (match, key) => { + if (match.includes("skip-")) return match; + + if (unusedKeys.includes(key)) { + return ` "skip-${key}":`; + } + return match; +}); + +writeFileSync(dictionaryPath, newDictionary); diff --git a/web/package.json b/web/package.json index b1c1da06..b04bd2fa 100644 --- a/web/package.json +++ b/web/package.json @@ -76,6 +76,7 @@ "generate:robots-txt": "npx tsx src/_build/gen-robots-txt.ts", "generate:sentry-release": "tsx ../packages/tooling/sentry-release.ts web bundle", "generate:sitemap": "npx tsx src/_build/sitemap.ts", + "prune:dictionary": "npx tsx ../packages/tooling/prune-dictionary.ts", "lh:collect": "npx --yes @lhci/cli collect", "lh:upload": "npx --yes @lhci/cli upload", "lint": "npm run build && npm run lint:alone", From 08f855fd559dc9b1b2bb618aebe59ad7c703d952 Mon Sep 17 00:00:00 2001 From: Zakaria Mansouri Date: Tue, 31 Dec 2024 01:31:09 +0100 Subject: [PATCH 2/2] refactor: remove unused dictionary entries and clean up code --- web/src/components/locale/dictionary.ts | 101 +----------------------- 1 file changed, 1 insertion(+), 100 deletions(-) diff --git a/web/src/components/locale/dictionary.ts b/web/src/components/locale/dictionary.ts index 9c273153..e52f732f 100644 --- a/web/src/components/locale/dictionary.ts +++ b/web/src/components/locale/dictionary.ts @@ -7,14 +7,10 @@ type DictionaryGroups = PyramidSplitString[number]; export type DictionaryKeys = AllDictionaryKeys & (`${G}-${string}` | `${G}`); -// @TODO-ZM: use a de-deduplication tool for repeated text - export const dictionary = { "navbar-section-contribute": { en: "Contribute", ar: "أساهم" }, "navbar-section-connect": { en: "Connect", ar: "أتواصل" }, - "navbar-section-learn": { en: "Learn", ar: "أتعلّم" }, "navbar-section-projects": { en: "Projects", ar: "مشاريع" }, - "navbar-section-articles": { en: "Articles", ar: "مقالات" }, "navbar-section-faq": { en: "FAQ", ar: "أسئلة / أجوبة" }, "navbar-section-search": { en: "Search...", ar: "بحث..." }, @@ -23,9 +19,7 @@ export const dictionary = { ar: "روابط مفيدة", }, "footer-category-link-text-home": { en: "Home", ar: "الصفحة الرئيسية" }, - "footer-category-link-text-learn": { en: "Learn", ar: "اتعلم" }, "footer-category-link-text-projects": { en: "Projects", ar: "مشاريع" }, - "footer-category-link-text-articles": { en: "Articles", ar: "مقالات" }, "footer-category-link-text-faq": { en: "FAQ", ar: "أسئلة / أجوبة" }, "footer-category-title-social-media": { en: "Social Media", @@ -50,10 +44,7 @@ export const dictionary = { en: "Frequently Asked Questions", ar: "الأسئلة الأكثر طرحًا", }, - "faq-need-help": { - en: "Still need help? send us an email at ", - ar: "هل ما زلت بحاجة إلى المساعدة؟ أرسل إلينا بريدًا إلكترونيًا على ", - }, + "faq-topic-1": { en: "General", ar: "أسئلة عامة", @@ -204,14 +195,6 @@ Besides the open tasks on [/contribute](/contribute) page, you can also contribu en: "Get to know our team 💻", ar: "تعرف على فريقنا 💻", }, - "team-card-cta-button": { - en: "Contributions", - ar: "المساهمات", - }, - "team-card-repositories": { - en: "Repositories", - ar: "مستودعات", - }, "contributor-title-pre": { en: "See the profile page of", ar: "انظر إلى صفحة الملف الشخصي لـ", @@ -264,10 +247,6 @@ Besides the open tasks on [/contribute](/contribute) page, you can also contribu en: "Other", ar: "أخرى", }, - "projects-card-cta-button": { - en: "Details", - ar: "تفاصيل", - }, "project-title-pre": { en: "See the details of", ar: "انظر إلى تفاصيل مشروع", @@ -328,11 +307,6 @@ Besides the open tasks on [/contribute](/contribute) page, you can also contribu en: "A broken link?", ar: "عنوان url معطل؟", }, - "notfound-subtitle": { - // @TODO-ZM: link to /contibutors/github/NurElHuda later when we have contibutors page - en: `Finally someone saw the 404 page Nour built 😄`, - ar: `أخيرًا شاهد شخص ما صفحة 404 التي أنشأتها نور 😄`, - }, "notfound-back-home": { en: "Go Back Home", ar: "ارجع إلى الصفحة الرئيسية", @@ -345,18 +319,6 @@ Besides the open tasks on [/contribute](/contribute) page, you can also contribu en: "Browse and contribute to Algerian open-source projects", ar: "تصفح وساهم في مشاريع جزائرية مفتوحة المصدر", }, - "contribute-filter-projects": { - en: "Project", - ar: "المشروع", - }, - "contribute-filter-languages": { - en: "Programming Language", - ar: "لغة البرمجة", - }, - "contribute-filter-labels": { - en: "Label", - ar: "الوسم", - }, "contribute-read-issue": { en: "Learn more", ar: "اقرأ المزيد", @@ -381,75 +343,14 @@ Besides the open tasks on [/contribute](/contribute) page, you can also contribu en: "y|mo|d|h|min|Just now", ar: " عام| شهر| يوم| ساعة| دقيقة| الآن", }, - "articles-title": { - en: "Read and discuss articles written by algerian developers | DzCode i/o", - ar: "اقرأ وناقش المقالات التي كتبها المطورون الجزائريون | DzCode i / o", - }, - "articles-description": { - en: "Browse, read or modify a growing list of articles written by Algerian developers, or Add your own article to the list!", - ar: "تصفح أو اقرأ أو عدل قائمة متزايدة من المقالات التي كتبها مطورون جزائريون ، أو أضف مقالك الخاص إلى القائمة!", - }, - "articles-content-back": { - en: "Back to the list", - ar: "عد إلى القائمة", - }, - "articles-content-authors": { - en: "This article is written by", - ar: "هذا المقال كتبه", - }, - "articles-content-contributors": { - en: "With the help of", - ar: "بمساعدة", - }, - - "learn-title": { - en: "Learn about software development through open-source | DzCode i/o", - ar: "تعرف على البرمجة من خلال البرامج مفتوحة المصدر | DzCode i / o", - }, - "learn-description": { - en: "Learn and share your knowledge with other Algerian developers!", - ar: "تعلم وشارك معرفتك مع مطورين جزائريين آخرين!", - }, - "learn-content-back": { - en: "Back to the list", - ar: "عد إلى القائمة", - }, - "learn-content-authors": { - en: "This article is written by", - ar: "هذا المقال كتبه", - }, - "learn-content-contributors": { - en: "With the help of", - ar: "بمساعدة", - }, - "ui-theme-DARK": { en: "Dark", ar: "داكن" }, - "ui-theme-LIGHT": { en: "Light", ar: "فاتح" }, - "ui-theme-AUTO": { en: "Auto", ar: "تلقائي" }, "global-generic-error": { en: "Oops, something went wrong, please try again...", ar: "عفوًا ، حدث خطأ ما ، يرجى المحاولة مرة أخرى ...", }, - "global-error-email-us": { - en: "Email us 📩", - ar: "راسلنا 📩", - }, "global-try-again": { en: "Try Again", ar: "حاول مرة أخري", }, - // @TODO-ZM: add other languages - "global-programming-language-javascript": { - en: "Javascript", - ar: "جافا سكريبت", - }, - "global-programming-language-typescript": { - en: "Typescript", - ar: "تايب سكريبت", - }, - "global-contribution-label-bug": { - en: "Bug", - ar: "خطأ", - }, "global-algeria-codes": { en: "Algeria Codes", ar: "الجزائر تبرمج",