feat: implement backend localization infrastructure
- Add internal/locale package: Parse(Accept-Language), FromContext/WithLang helpers, 12 supported languages - Add Language middleware that reads Accept-Language header and stores lang in context - Register Language middleware globally in server router (after CORS) Database migrations: - 009: create recipe_translations, saved_recipe_translations, ingredient_translations tables; migrate existing _ru data - 010: drop legacy _ru columns (title_ru, description_ru, canonical_name_ru); update FTS index Models: remove all _ru fields (TitleRu, DescriptionRu, NameRu, UnitRu, CanonicalNameRu) Repositories: - recipe: Upsert drops _ru params; GetByID does LEFT JOIN COALESCE on recipe_translations; ListMissingTranslation(lang); UpsertTranslation - ingredient: same pattern with ingredient_translations; Search now queries translated names/aliases - savedrecipe: List/GetByID LEFT JOIN COALESCE on saved_recipe_translations; UpsertTranslation Gemini: - RecipeRequest/MenuRequest gain Lang field - buildRecipePrompt rewritten in English with target-language content instruction; image_query always in English - GenerateMenu propagates Lang to GenerateRecipes Handlers: - recommendation/menu: pass locale.FromContext(ctx) as Lang - recognition: saveClassification stores Russian translation via UpsertTranslation instead of _ru column Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/food-ai/backend/internal/gemini"
|
||||
"github.com/food-ai/backend/internal/locale"
|
||||
"github.com/food-ai/backend/internal/middleware"
|
||||
"github.com/food-ai/backend/internal/user"
|
||||
)
|
||||
@@ -74,7 +75,7 @@ func (h *Handler) GetRecommendations(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
req := buildRecipeRequest(u, count)
|
||||
req := buildRecipeRequest(u, count, locale.FromContext(r.Context()))
|
||||
|
||||
// Attach available products to personalise the prompt.
|
||||
if products, err := h.productLister.ListForPrompt(r.Context(), userID); err == nil {
|
||||
@@ -108,10 +109,11 @@ func (h *Handler) GetRecommendations(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, recipes)
|
||||
}
|
||||
|
||||
func buildRecipeRequest(u *user.User, count int) gemini.RecipeRequest {
|
||||
func buildRecipeRequest(u *user.User, count int, lang string) gemini.RecipeRequest {
|
||||
req := gemini.RecipeRequest{
|
||||
Count: count,
|
||||
DailyCalories: 2000, // sensible default
|
||||
Lang: lang,
|
||||
}
|
||||
|
||||
if u.Goal != nil {
|
||||
|
||||
Reference in New Issue
Block a user