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:
dbastrikin
2026-03-10 23:08:10 +02:00
parent a225f6c47a
commit e1fbe7b1a2
10 changed files with 161 additions and 58 deletions

View File

@@ -5,6 +5,8 @@ import (
"encoding/json"
"fmt"
"strings"
"github.com/food-ai/backend/internal/locale"
)
// RecipeGenerator generates recipes using the Gemini AI.
@@ -63,22 +65,6 @@ type NutritionInfo struct {
Approximate bool `json:"approximate"`
}
// langNames maps ISO 639-1 codes to English language names used in the prompt.
var langNames = map[string]string{
"en": "English",
"ru": "Russian",
"es": "Spanish",
"de": "German",
"fr": "French",
"it": "Italian",
"pt": "Portuguese",
"zh": "Chinese (Simplified)",
"ja": "Japanese",
"ko": "Korean",
"ar": "Arabic",
"hi": "Hindi",
}
// goalNames maps internal goal codes to English descriptions used in the prompt.
var goalNames = map[string]string{
"lose": "weight loss",
@@ -130,9 +116,12 @@ func buildRecipePrompt(req RecipeRequest) string {
if lang == "" {
lang = "en"
}
langName, ok := langNames[lang]
if !ok {
langName = "English"
langName := "English"
for _, l := range locale.Languages {
if l.Code == lang {
langName = l.EnglishName
break
}
}
goal := goalNames[req.UserGoal]