Skip to content

Commit

Permalink
chore: mark GinI18n recievers as public (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivincent authored Nov 9, 2024
1 parent 41ab163 commit a574d63
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions ginI18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ginI18nImpl struct {
}

// getMessage get localize message by lng and messageID
func (i *ginI18nImpl) getMessage(ctx *gin.Context, param interface{}) (string, error) {
func (i *ginI18nImpl) GetMessage(ctx *gin.Context, param interface{}) (string, error) {
lng := i.getLngHandler(ctx, i.defaultLanguage.String())
localizer := i.getLocalizerByLng(lng)

Expand All @@ -38,12 +38,12 @@ func (i *ginI18nImpl) getMessage(ctx *gin.Context, param interface{}) (string, e
}

// mustGetMessage ...
func (i *ginI18nImpl) mustGetMessage(ctx *gin.Context, param interface{}) string {
message, _ := i.getMessage(ctx, param)
func (i *ginI18nImpl) MustGetMessage(ctx *gin.Context, param interface{}) string {
message, _ := i.GetMessage(ctx, param)
return message
}

func (i *ginI18nImpl) setBundle(cfg *BundleCfg) {
func (i *ginI18nImpl) SetBundle(cfg *BundleCfg) {
bundle := i18n.NewBundle(cfg.DefaultLanguage)
bundle.RegisterUnmarshalFunc(cfg.FormatBundleFile, cfg.UnmarshalFunc)

Expand All @@ -54,7 +54,7 @@ func (i *ginI18nImpl) setBundle(cfg *BundleCfg) {
i.setLocalizerByLng(cfg.AcceptLanguage)
}

func (i *ginI18nImpl) setGetLngHandler(handler GetLngHandler) {
func (i *ginI18nImpl) SetGetLngHandler(handler GetLngHandler) {
i.getLngHandler = handler
}

Expand Down
6 changes: 3 additions & 3 deletions i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newI18n(opts ...Option) GinI18n {

// if bundle isn't constructed then assign it from default
if ins.bundle == nil {
ins.setBundle(defaultBundleConfig)
ins.SetBundle(defaultBundleConfig)
}

// if getLngHandler isn't constructed then assign it from default
Expand Down Expand Up @@ -48,7 +48,7 @@ func Localize(opts ...Option) gin.HandlerFunc {
// })
func GetMessage(context *gin.Context, param interface{}) (string, error) {
atI18n := context.Value("i18n").(GinI18n)
return atI18n.getMessage(context, param)
return atI18n.GetMessage(context, param)
}

// MustGetMessage get the i18n message without error handling
Expand All @@ -64,5 +64,5 @@ func GetMessage(context *gin.Context, param interface{}) (string, error) {
// })
func MustGetMessage(context *gin.Context, param interface{}) string {
atI18n := context.MustGet("i18n").(GinI18n)
return atI18n.mustGetMessage(context, param)
return atI18n.MustGetMessage(context, param)
}
8 changes: 4 additions & 4 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

// GinI18n ...
type GinI18n interface {
getMessage(context *gin.Context, param interface{}) (string, error)
mustGetMessage(context *gin.Context, param interface{}) string
setBundle(cfg *BundleCfg)
setGetLngHandler(handler GetLngHandler)
GetMessage(context *gin.Context, param interface{}) (string, error)
MustGetMessage(context *gin.Context, param interface{}) string
SetBundle(cfg *BundleCfg)
SetGetLngHandler(handler GetLngHandler)
}
4 changes: 2 additions & 2 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func WithBundle(config *BundleCfg) Option {
if config.Loader == nil {
config.Loader = defaultLoader
}
g.setBundle(config)
g.SetBundle(config)
}
}

Expand All @@ -39,6 +39,6 @@ func WithBundle(config *BundleCfg) Option {
// This option allows you to customize how the current language is determined.
func WithGetLngHandle(handler GetLngHandler) Option {
return func(g GinI18n) {
g.setGetLngHandler(handler)
g.SetGetLngHandler(handler)
}
}

0 comments on commit a574d63

Please sign in to comment.