多语言支持

This commit is contained in:
ytc1012
2025-11-24 14:01:01 +08:00
parent bf21dba275
commit 57ef852863
32 changed files with 5255 additions and 36 deletions

View File

@@ -23,7 +23,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
final sessions = _storageService.getAllSessions();
final todayTotal = _storageService.getTodayTotalMinutes();
final todayDistractions = _storageService.getTodayDistractionCount();
final todayCompleted = _storageService.getTodayCompletedCount();
final todaySessions = _storageService.getTodaySessionsCount();
// Group sessions by date
final sessionsByDate = <DateTime, List<FocusSession>>{};
@@ -59,7 +59,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
l10n,
todayTotal,
todayDistractions,
todayCompleted,
todaySessions,
),
const SizedBox(height: 24),
@@ -108,7 +108,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
);
}
Widget _buildTodaySummary(AppLocalizations l10n, int totalMins, int distractions, int completed) {
Widget _buildTodaySummary(AppLocalizations l10n, int totalMins, int distractions, int sessions) {
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
@@ -140,7 +140,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
borderRadius: BorderRadius.circular(12),
),
child: Text(
l10n.sessions(completed),
l10n.sessions(sessions),
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 14,

View File

@@ -116,9 +116,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_buildSection(
title: l10n.language,
children: [
_buildLanguageOption(l10n, 'en', l10n.english),
const Divider(color: AppColors.divider),
_buildLanguageOption(l10n, 'zh', l10n.chinese),
_buildLanguageDropdown(l10n),
],
),
@@ -310,27 +308,57 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
Widget _buildLanguageOption(AppLocalizations l10n, String localeCode, String label) {
final isSelected = _selectedLocale == localeCode;
Widget _buildLanguageDropdown(AppLocalizations l10n) {
// Language options with their codes and display names
final languages = {
'en': l10n.english,
'zh': l10n.chinese,
'ja': l10n.japanese,
'ko': l10n.korean,
'es': l10n.spanish,
'de': l10n.german,
'fr': l10n.french,
'pt': l10n.portuguese,
'ru': l10n.russian,
'hi': l10n.hindi,
'id': l10n.indonesian,
'it': l10n.italian,
'ar': l10n.arabic,
};
return ListTile(
contentPadding: EdgeInsets.zero,
title: Text(
label,
style: TextStyle(
fontFamily: 'Nunito',
fontSize: 16,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
color: isSelected ? AppColors.primary : AppColors.textPrimary,
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
decoration: BoxDecoration(
color: AppColors.background,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppColors.divider),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: _selectedLocale,
isExpanded: true,
icon: const Icon(Icons.arrow_drop_down, color: AppColors.primary),
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
dropdownColor: AppColors.white,
borderRadius: BorderRadius.circular(12),
items: languages.entries.map((entry) {
return DropdownMenuItem<String>(
value: entry.key,
child: Text(entry.value),
);
}).toList(),
onChanged: (String? newValue) {
if (newValue != null) {
_saveLocale(newValue);
}
},
),
),
trailing: isSelected
? const Icon(
Icons.check_circle,
color: AppColors.primary,
)
: null,
onTap: () => _saveLocale(localeCode),
);
}