mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-10-28 01:48:51 +05:00
feat: add ?lang=en support to API with default ru
Language Support:
- Create GetLanguage() helper function
- Support both 'lang' and 'language' query parameters
- Convert short codes (en/ru) to TMDB format (en-US/ru-RU)
- Default language: ru-RU
Changes:
- pkg/handlers/lang_helper.go: new helper for language detection
- pkg/handlers/movie.go: use GetLanguage() in all endpoints
- pkg/handlers/tv.go: use GetLanguage() in all endpoints
How to use:
- ?lang=en → returns English content
- ?lang=ru → returns Russian content (default)
- No param → defaults to Russian
All movie/TV endpoints now support multilingual content:
GET /api/v1/movies/{id}?lang=en
GET /api/v1/movies/popular?lang=en
GET /api/v1/tv/{id}?lang=en
etc.
This commit is contained in:
35
pkg/handlers/lang_helper.go
Normal file
35
pkg/handlers/lang_helper.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetLanguage extracts the lang parameter from request and returns it with default "ru"
|
||||
// Supports both "lang" and "language" query parameters
|
||||
// Valid values: "ru", "en"
|
||||
// Default: "ru"
|
||||
func GetLanguage(r *http.Request) string {
|
||||
// Check "lang" parameter first (our new standard)
|
||||
lang := r.URL.Query().Get("lang")
|
||||
|
||||
// Fall back to "language" for backward compatibility
|
||||
if lang == "" {
|
||||
lang = r.URL.Query().Get("language")
|
||||
}
|
||||
|
||||
// Default to "ru" if not specified
|
||||
if lang == "" {
|
||||
return "ru-RU"
|
||||
}
|
||||
|
||||
// Convert short codes to TMDB format
|
||||
switch lang {
|
||||
case "en":
|
||||
return "en-US"
|
||||
case "ru":
|
||||
return "ru-RU"
|
||||
default:
|
||||
// Return as-is if already in correct format
|
||||
return lang
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user