42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
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)
|
|
|