import re files_to_fix = [ 'components/note-inline-editor.tsx', 'components/notes-tabs-view.tsx', 'components/note-card.tsx' ] replacement_func = """import { faIR } from 'date-fns/locale' function getDateLocale(language: string) { if (language === 'fr') return fr if (language === 'fa') return faIR return enUS }""" for file in files_to_fix: with open(file, 'r') as f: content = f.read() # 1. Replace the getDateLocale function content = re.sub( r'function getDateLocale\(language: string\) \{\s*if \(language === \'fr\'\) return fr\s*return enUS\s*\}', "function getDateLocale(language: string) {\n if (language === 'fr') return fr;\n if (language === 'fa') return require('date-fns/locale').faIR;\n return enUS;\n}", content ) # Also fix translations for "Modifiée" and "Créée" in inline editor (they are currently hardcoded) if 'note-inline-editor.tsx' in file: content = content.replace( "Modifiée {formatDistanceToNow(new Date(note.updatedAt), { addSuffix: true, locale: dateLocale })}", "{t('notes.modified') || 'Modifiée'} {formatDistanceToNow(new Date(note.updatedAt), { addSuffix: true, locale: dateLocale })}" ) content = content.replace( "Créée {formatDistanceToNow(new Date(note.createdAt), { addSuffix: true, locale: dateLocale })}", "{t('notes.created') || 'Créée'} {formatDistanceToNow(new Date(note.createdAt), { addSuffix: true, locale: dateLocale })}" ) with open(file, 'w') as f: f.write(content)