chore: snapshot before performance optimization
This commit is contained in:
41
keep-notes/fix_date_locale.py
Normal file
41
keep-notes/fix_date_locale.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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(
|
||||
"<span>Modifiée {formatDistanceToNow(new Date(note.updatedAt), { addSuffix: true, locale: dateLocale })}</span>",
|
||||
"<span>{t('notes.modified') || 'Modifiée'} {formatDistanceToNow(new Date(note.updatedAt), { addSuffix: true, locale: dateLocale })}</span>"
|
||||
)
|
||||
content = content.replace(
|
||||
"<span>Créée {formatDistanceToNow(new Date(note.createdAt), { addSuffix: true, locale: dateLocale })}</span>",
|
||||
"<span>{t('notes.created') || 'Créée'} {formatDistanceToNow(new Date(note.createdAt), { addSuffix: true, locale: dateLocale })}</span>"
|
||||
)
|
||||
|
||||
with open(file, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
Reference in New Issue
Block a user