feat: move supported languages to DB table, expose via GET /languages
- migration 013: create languages table (code PK, native_name, english_name, is_active, sort_order) with all 12 existing languages seeded - locale: add Language struct, Languages []Language, LoadFromDB() — queries languages table at startup and populates both Supported map and Languages slice; existing Parse/FromContext/FromRequest unchanged - main.go: call locale.LoadFromDB after pool is ready - gemini/recipe.go: remove hardcoded langNames map, use locale.Languages linear lookup for English name in prompt - language/handler.go: new package with GET /languages handler returning active languages list (no auth required) - server.go: register GET /languages as public route - Flutter: add LanguageRepository + languageRepositoryProvider that fetches /languages from backend - language_provider.dart: replace const supportedLanguages map with supportedLanguagesProvider (FutureProvider) backed by LanguageRepository - profile_provider.dart: remove supportedLanguages.containsKey validation — backend is source of truth; sync any non-empty language from preferences - profile_screen.dart: use supportedLanguagesProvider for display name and dropdown (async with loading/error states) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
22
client/lib/core/api/language_repository.dart
Normal file
22
client/lib/core/api/language_repository.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../auth/auth_provider.dart';
|
||||
import 'api_client.dart';
|
||||
|
||||
class LanguageRepository {
|
||||
final ApiClient _api;
|
||||
LanguageRepository(this._api);
|
||||
|
||||
Future<Map<String, String>> fetchLanguages() async {
|
||||
final response = await _api.dio.get('/languages');
|
||||
final List<dynamic> items = response.data['languages'] as List;
|
||||
return {
|
||||
for (final item in items)
|
||||
item['code'] as String: item['native_name'] as String,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
final languageRepositoryProvider = Provider<LanguageRepository>(
|
||||
(ref) => LanguageRepository(ref.watch(apiClientProvider)),
|
||||
);
|
||||
@@ -1,21 +1,12 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// Supported ISO 639-1 language codes with their native names.
|
||||
/// Must match the backend locale.Supported map.
|
||||
const supportedLanguages = <String, String>{
|
||||
'en': 'English',
|
||||
'ru': 'Русский',
|
||||
'es': 'Español',
|
||||
'de': 'Deutsch',
|
||||
'fr': 'Français',
|
||||
'it': 'Italiano',
|
||||
'pt': 'Português',
|
||||
'zh': '中文',
|
||||
'ja': '日本語',
|
||||
'ko': '한국어',
|
||||
'ar': 'العربية',
|
||||
'hi': 'हिन्दी',
|
||||
};
|
||||
import '../api/language_repository.dart';
|
||||
|
||||
/// Fetches and caches the supported languages from the backend.
|
||||
/// Returns a map of code → native name (e.g. {'en': 'English', 'ru': 'Русский'}).
|
||||
final supportedLanguagesProvider = FutureProvider<Map<String, String>>((ref) {
|
||||
return ref.watch(languageRepositoryProvider).fetchLanguages();
|
||||
});
|
||||
|
||||
/// Current app language (ISO 639-1 code).
|
||||
/// Synced from user.preferences['language'] after the profile loads or is updated.
|
||||
|
||||
Reference in New Issue
Block a user