refactor(localization): update task-related translations and improve user activity feed

- Added new translation keys for recent tasks and time logged tasks in Albanian, German, English, Spanish, Portuguese, and Chinese localization files.
- Enhanced user activity feed to switch between recent tasks and time logged tasks, improving user experience.
- Updated the date formatting utility to support locale-specific formatting for better internationalization.
- Refactored task activity list and time logged task list components to utilize a table layout for improved readability.
This commit is contained in:
chamikaJ
2025-07-29 10:19:28 +05:30
parent e8ccc2a533
commit 53a28cf489
13 changed files with 347 additions and 387 deletions

View File

@@ -1,32 +1,59 @@
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import 'dayjs/locale/de';
import 'dayjs/locale/es';
import 'dayjs/locale/pt';
import 'dayjs/locale/zh-cn';
import { getLanguageFromLocalStorage } from './language-utils';
// Initialize the relativeTime plugin
// Initialize plugins
dayjs.extend(relativeTime);
dayjs.extend(localizedFormat);
/**
* Formats a date to a relative time string (e.g., "2 hours ago", "a day ago")
* This mimics the Angular fromNow pipe functionality
*
* @param date - The date to format (string, Date, or dayjs object)
* @returns A string representing the relative time
*/
export const fromNow = (date: string | Date | dayjs.Dayjs): string => {
if (!date) return '';
return dayjs(date).fromNow();
// Map application languages to dayjs locales
const getLocaleFromLanguage = (language: string): string => {
const localeMap: Record<string, string> = {
'en': 'en',
'de': 'de',
'es': 'es',
'pt': 'pt',
'alb': 'en', // Albanian not supported by dayjs, fallback to English
'zh': 'zh-cn'
};
return localeMap[language] || 'en';
};
/**
* Formats a date to a specific format
* Formats a date to a relative time string (e.g., "2 hours ago", "a day ago")
* This mimics the Angular fromNow pipe functionality with locale support
*
* @param date - The date to format (string, Date, or dayjs object)
* @param language - Optional language override (defaults to stored language)
* @returns A string representing the relative time
*/
export const fromNow = (date: string | Date | dayjs.Dayjs, language?: string): string => {
if (!date) return '';
const currentLanguage = language || getLanguageFromLocalStorage();
const locale = getLocaleFromLanguage(currentLanguage);
return dayjs(date).locale(locale).fromNow();
};
/**
* Formats a date to a specific format with locale support
*
* @param date - The date to format (string, Date, or dayjs object)
* @param format - The format string (default: 'YYYY-MM-DD')
* @param language - Optional language override (defaults to stored language)
* @returns A formatted date string
*/
export const formatDate = (
date: string | Date | dayjs.Dayjs,
format: string = 'YYYY-MM-DD'
format: string = 'YYYY-MM-DD',
language?: string
): string => {
if (!date) return '';
return dayjs(date).format(format);
const currentLanguage = language || getLanguageFromLocalStorage();
const locale = getLocaleFromLanguage(currentLanguage);
return dayjs(date).locale(locale).format(format);
};