Beispiel #1
0
Datei: i18n.go Projekt: qor/i18n
func getLocaleFromContext(context *qor.Context) string {
	if locale := utils.GetLocale(context); locale != "" {
		return locale
	}

	return Default
}
Beispiel #2
0
func Router() *http.ServeMux {
	if rootMux == nil {
		router := gin.Default()
		router.Use(func(ctx *gin.Context) {
			if locale := utils.GetLocale(&qor.Context{Request: ctx.Request, Writer: ctx.Writer}); locale != "" {
				ctx.Set("DB", db.DB.Set("l10n:locale", locale))
			}
		})
		gin.SetMode(gin.DebugMode)

		router.GET("/", controllers.HomeIndex)
		router.GET("/products/:code", controllers.ProductShow)
		router.GET("/switch_locale", controllers.SwitchLocale)

		rootMux = http.NewServeMux()
		rootMux.Handle("/auth/", auth.Auth.NewRouter())
		publicDir := http.Dir(strings.Join([]string{config.Root, "public"}, "/"))
		rootMux.Handle("/dist/", http.FileServer(publicDir))
		rootMux.Handle("/vendors/", http.FileServer(publicDir))
		rootMux.Handle("/images/", http.FileServer(publicDir))
		rootMux.Handle("/fonts/", http.FileServer(publicDir))

		WildcardRouter = wildcard_router.New()
		WildcardRouter.MountTo("/", rootMux)
		WildcardRouter.AddHandler(router)
	}
	return rootMux
}
Beispiel #3
0
func (context *Context) dt(key string, value string, values ...interface{}) string {
	locale := utils.GetLocale(context.Context)

	if context.Admin.I18n == nil {
		if result, err := cldr.Parse(locale, value, values...); err == nil {
			return result
		}
		return key
	} else {
		return context.Admin.I18n.Scope("qor_admin").Default(value).T(locale, key, values...)
	}
}
Beispiel #4
0
func (admin *Admin) T(context *qor.Context, key string, value string, values ...interface{}) template.HTML {
	locale := utils.GetLocale(context)

	if admin.I18n == nil {
		if result, err := cldr.Parse(locale, value, values...); err == nil {
			return template.HTML(result)
		}
		return template.HTML(key)
	} else {
		return admin.I18n.Scope("qor_admin").Default(value).T(locale, key, values...)
	}
}