diff --git a/src/components/Calendar/CalendarGrid.tsx b/src/components/Calendar/CalendarGrid.tsx index a3f12b7..f57e31a 100644 --- a/src/components/Calendar/CalendarGrid.tsx +++ b/src/components/Calendar/CalendarGrid.tsx @@ -2,9 +2,19 @@ import React from 'react'; import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; import dayjs from 'dayjs'; +import { useTranslation } from 'react-i18next'; import CalendarDay from './CalendarDay'; import { Task } from '../../services/taskService'; +const MONTH_KEYS = [ + 'january', 'february', 'march', 'april', 'may', 'june', + 'july', 'august', 'september', 'october', 'november', 'december' +]; + +const WEEKDAY_KEYS = [ + 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' +]; + export interface CalendarGridProps { selectedDate: string; tasks: Task[]; @@ -26,6 +36,7 @@ const CalendarGrid: React.FC = ({ onPreviousMonth, onNextMonth }) => { + const { t } = useTranslation(); // Gruppo gli impegni per data const groupTasksByDate = () => { const groupedTasks: Record = {}; @@ -130,7 +141,7 @@ const CalendarGrid: React.FC = ({ - {dayjs(selectedDate).format('MMMM YYYY')} + {t(`calendar.months.${MONTH_KEYS[dayjs(selectedDate).month()]}`)} {dayjs(selectedDate).year()} @@ -140,9 +151,9 @@ const CalendarGrid: React.FC = ({ {/* Giorni della settimana */} - {['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'].map((day, index) => ( - - {day} + {WEEKDAY_KEYS.map((dayKey) => ( + + {t(`calendar.days.${dayKey}`)} ))} diff --git a/src/components/Calendar/CalendarView.tsx b/src/components/Calendar/CalendarView.tsx index a0a2a75..e7fd6c7 100644 --- a/src/components/Calendar/CalendarView.tsx +++ b/src/components/Calendar/CalendarView.tsx @@ -15,6 +15,11 @@ import AddTaskButton from '../Task/AddTaskButton'; import { addTaskToList } from '../TaskList/types'; import { LoadingState, EmptyState, StatusChip, AppText } from '../UI/foundation'; +const MONTH_KEYS = [ + 'january', 'february', 'march', 'april', 'may', 'june', + 'july', 'august', 'september', 'october', 'november', 'december' +]; + const CalendarView: React.FC = () => { const [selectedDate, setSelectedDate] = useState(dayjs().format('YYYY-MM-DD')); const [tasks, setTasks] = useState([]); @@ -292,7 +297,7 @@ const CalendarView: React.FC = () => { fetchTasks(); } catch (error) { console.error("Errore nel completamento del task:", error); - Alert.alert("Errore", "Impossibile completare il task. Riprova."); + Alert.alert(t('calendar.errors.title'), t('calendar.errors.completeFailed')); } }; @@ -309,7 +314,7 @@ const CalendarView: React.FC = () => { fetchTasks(); } catch (error) { console.error("Errore nell'annullamento del completamento del task:", error); - Alert.alert("Errore", "Impossibile riaprire il task. Riprova."); + Alert.alert(t('calendar.errors.title'), t('calendar.errors.reopenFailed')); } }; @@ -326,7 +331,7 @@ const CalendarView: React.FC = () => { fetchTasks(); } catch (error) { console.error("Errore nella modifica del task:", error); - Alert.alert("Errore", "Impossibile modificare il task. Riprova."); + Alert.alert(t('calendar.errors.title'), t('calendar.errors.editFailed')); } }; @@ -362,8 +367,7 @@ const CalendarView: React.FC = () => { categoryNameParam?: string ) => { const priorityString = priority === 1 ? "Bassa" : priority === 2 ? "Media" : "Alta"; - // Costruisci nuovo task con data di inizio dal calendario - const category = categoryNameParam || "Calendario"; + const category = categoryNameParam || t('calendar.defaultCategory'); const newTask = { id: Date.now(), title: title.trim(), @@ -389,8 +393,8 @@ const CalendarView: React.FC = () => { console.error("Errore aggiunta task nel calendario:", error); addTaskToList(newTask, category); Alert.alert( - "Attenzione", - "Task aggiunto localmente ma errore nel salvataggio sul server." + t('calendar.errors.warningTitle'), + t('calendar.errors.localSaveWarning') ); setShowAddTask(false); } @@ -412,14 +416,14 @@ const CalendarView: React.FC = () => { - Impegni del {dayjs(selectedDate).format('DD MMMM YYYY')} + {t('calendar.commitmentsOf')} {dayjs(selectedDate).format('DD')} {t(`calendar.months.${MONTH_KEYS[dayjs(selectedDate).month()]}`)} {dayjs(selectedDate).year()} {/* Componente di caricamento */} - + {/* Componente AddTask */} { onClose={handleCloseAddTask} onSave={handleSaveTask} allowCategorySelection={true} - categoryName="Calendario" + categoryName={t('calendar.defaultCategory')} initialDate={selectedDate} /> @@ -449,13 +453,13 @@ const CalendarView: React.FC = () => { - Impegni del {dayjs(selectedDate).format('DD MMMM YYYY')} + {t('calendar.commitmentsOf')} {dayjs(selectedDate).format('DD')} {t(`calendar.months.${MONTH_KEYS[dayjs(selectedDate).month()]}`)} {dayjs(selectedDate).year()} {syncStatus && (syncStatus.isSyncing || syncStatus.pendingChanges > 0) && ( {syncStatus.isSyncing ? ( } /> @@ -487,7 +491,7 @@ const CalendarView: React.FC = () => { ) : ( } - title="Nessun impegno per questa data" + title={t('calendar.noEventsForDate')} style={styles.noTasksContainer} /> )} @@ -499,7 +503,7 @@ const CalendarView: React.FC = () => { onClose={handleCloseAddTask} onSave={handleSaveTask} allowCategorySelection={true} - categoryName="Calendario" + categoryName={t('calendar.defaultCategory')} initialDate={selectedDate} /> diff --git a/src/components/Calendar20/AgendaView.tsx b/src/components/Calendar20/AgendaView.tsx index d04a7c7..b323d52 100644 --- a/src/components/Calendar20/AgendaView.tsx +++ b/src/components/Calendar20/AgendaView.tsx @@ -106,7 +106,7 @@ const AgendaView: React.FC = ({ if (mins < 60) return `${mins} min`; const h = Math.floor(mins / 60); const m = mins % 60; - if (m === 0) return h === 1 ? '1 ora' : `${h} ore`; + if (m === 0) return h === 1 ? t('calendar20.duration.hour') : t('calendar20.duration.hours', { count: h }); return `${h}h ${m}min`; })(); @@ -186,7 +186,7 @@ const AgendaView: React.FC = ({ ListFooterComponent={ - Load more + {t('calendar20.loadMore')} } /> diff --git a/src/components/Calendar20/Calendar20View.tsx b/src/components/Calendar20/Calendar20View.tsx index 83a07fc..6645c65 100644 --- a/src/components/Calendar20/Calendar20View.tsx +++ b/src/components/Calendar20/Calendar20View.tsx @@ -22,6 +22,7 @@ import FABMenu from './FABMenu'; import AddTask from '../Task/AddTask'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { LoadingState } from '../UI/foundation'; +import { useTranslation } from 'react-i18next'; dayjs.extend(isoWeek); @@ -32,6 +33,7 @@ interface Calendar20ViewProps { } const Calendar20View: React.FC = ({ onClose }) => { + const { t } = useTranslation(); const [viewType, setViewType] = useState('month'); const [currentDate, setCurrentDate] = useState(dayjs()); const [rawTasks, setRawTasks] = useState([]); @@ -273,7 +275,7 @@ const Calendar20View: React.FC = ({ onClose }) => { ) => { const { addTask } = await import('../../services/taskService'); const priorityString = priority === 1 ? 'Bassa' : priority === 2 ? 'Media' : 'Alta'; - const category = categoryNameParam || 'Calendario'; + const category = categoryNameParam || t('calendar.defaultCategory'); // Usa la data selezionata se disponibile, altrimenti usa la data corrente const taskDate = selectedDateForTask || currentDate; const newTask: Task = { @@ -416,7 +418,7 @@ const Calendar20View: React.FC = ({ onClose }) => { }} onSave={handleSaveTask} allowCategorySelection={true} - categoryName="Calendario" + categoryName={t('calendar.defaultCategory')} initialDate={(selectedDateForTask || currentDate).format('YYYY-MM-DD')} />