1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package mapper
- import (
- "github.com/gofiber/fiber/v2"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/models"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
- )
- func ToLanguage(lang models.Language) i18n.Language {
- switch lang {
- case models.LangRu:
- return i18n.Ru
- case models.LangEn:
- return i18n.En
- default:
- return ""
- }
- }
- func ToLanguageModel(lang i18n.Language) models.Language {
- switch lang {
- case i18n.Ru:
- return models.LangRu
- case i18n.En:
- return models.LangEn
- default:
- return 0
- }
- }
- func ToLanguageFromString(lang string) i18n.Language {
- switch lang {
- case "en", "EN":
- return i18n.En
- case "ru", "RU":
- return i18n.Ru
- default:
- return ""
- }
- }
- func LanguageFromContext(c *fiber.Ctx) i18n.Language {
- language := ToLanguageFromString(c.Params(i18n.LangParam))
- if len(language) == 0 {
- language = i18n.Default
- }
- return language
- }
|