Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: prune dictionary #630

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/tooling/prune-dictionary.ts
Original file line number Diff line number Diff line change
@@ -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<Record<string, unknown>>((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);
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
101 changes: 1 addition & 100 deletions web/src/components/locale/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ type DictionaryGroups = PyramidSplitString<AllDictionaryKeys, "-">[number];
export type DictionaryKeys<G extends DictionaryGroups> = 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: "بحث..." },

Expand All @@ -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",
Expand All @@ -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: "أسئلة عامة",
Expand Down Expand Up @@ -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: "انظر إلى صفحة الملف الشخصي لـ",
Expand Down Expand Up @@ -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: "انظر إلى تفاصيل مشروع",
Expand Down Expand Up @@ -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 <a href="https://github.com/NurElHuda">Nour</a> built 😄`,
ar: `أخيرًا شاهد شخص ما صفحة 404 التي أنشأتها <a href="https://github.com/NurElHuda">نور</a> 😄`,
},
"notfound-back-home": {
en: "Go Back Home",
ar: "ارجع إلى الصفحة الرئيسية",
Expand All @@ -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: "اقرأ المزيد",
Expand All @@ -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: "الجزائر تبرمج",
Expand Down
Loading