refactor: clean up codebase by removing redundant comments

Remove unnecessary JSDoc comments and redundant explanations from components, types, and data files. Simplify code structure while maintaining functionality.

Clean up language handling logic in components by removing redundant comments and simplifying state management. Move type imports to dedicated type import statements where applicable.
This commit is contained in:
joyzhao
2025-06-21 09:28:10 +08:00
parent ea01dc6dd8
commit 67f713565a
15 changed files with 9 additions and 168 deletions

View File

@@ -1,25 +1,9 @@
/**
* Translations module
* Contains all translation data for the application
*/
/**
* Available languages in the application
*/
export const languages = {
en: 'English',
zh: '简体中文',
} as const;
/**
* Default language for the application
*/
export const defaultLang = 'en';
/**
* Structured translations data
* Organized by language and feature area
*/
export const translations = {
en: {
nav: {

View File

@@ -1,44 +1,18 @@
/**
* Internationalization utilities module
* Contains helper functions for i18n functionality
*/
import { defaultLang, languages, flatTranslations } from './translations';
import type { Lang } from '@/types/i18n';
/**
* Translation key type
* Represents a dot-notation path to a translation string
*/
export type TranslationKey = string;
/**
* Get translation function
* Returns a function that can be used to get translations for a specific language
*
* @param lang - The language to get translations for
* @returns A translation function
*/
export function useTranslations(lang: Lang | undefined) {
const currentLang = lang || defaultLang;
/**
* Translation function
* Gets a translation string for the specified key and replaces placeholders
*
* @param key - The translation key (dot notation)
* @param args - Optional arguments to replace placeholders in the translation
* @returns The translated string
*/
return function t(key: TranslationKey, ...args: any[]): string {
// Get translation from flattened translations for better performance
let translation = flatTranslations[currentLang][key];
// Fallback to default language if translation not found
if (!translation && currentLang !== defaultLang) {
translation = flatTranslations[defaultLang][key];
}
// Fallback to key if translation not found in any language
if (!translation) {
console.warn(`Translation key not found: ${key}`);
return key;