mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/language' into 'test'
feat: add default language option See merge request opensource/answer!174
This commit is contained in:
commit
b597bd43b8
|
@ -21,8 +21,13 @@ type LangOption struct {
|
|||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// LanguageOptions language
|
||||
var LanguageOptions []*LangOption
|
||||
// DefaultLangOption default language option. If user config the language is default, the language option is admin choose.
|
||||
const DefaultLangOption = "Default"
|
||||
|
||||
var (
|
||||
// LanguageOptions language
|
||||
LanguageOptions []*LangOption
|
||||
)
|
||||
|
||||
// NewTranslator new a translator
|
||||
func NewTranslator(c *I18n) (tr i18n.Translator, err error) {
|
||||
|
@ -49,6 +54,9 @@ func NewTranslator(c *I18n) (tr i18n.Translator, err error) {
|
|||
|
||||
// CheckLanguageIsValid check user input language is valid
|
||||
func CheckLanguageIsValid(lang string) bool {
|
||||
if lang == DefaultLangOption {
|
||||
return true
|
||||
}
|
||||
for _, option := range LanguageOptions {
|
||||
if option.Value == lang {
|
||||
return true
|
||||
|
|
|
@ -64,7 +64,7 @@ func (u *LangController) GetUserLangOptions(ctx *gin.Context) {
|
|||
options := translator.LanguageOptions
|
||||
if len(siteInterfaceResp.Language) > 0 {
|
||||
defaultOption := []*translator.LangOption{
|
||||
{Label: "Default", Value: siteInterfaceResp.Language},
|
||||
{Label: translator.DefaultLangOption, Value: siteInterfaceResp.Language},
|
||||
}
|
||||
options = append(defaultOption, options...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue