Skip to content

Commit

Permalink
docs: improve code documentation and comments
Browse files Browse the repository at this point in the history
- Update comments for `BundleCfg` fields to include descriptions of their purposes
- Add detailed comments to `WithBundle` and `WithGetLngHandle` functions explaining their behavior and defaults
- Remove placeholder comments without descriptions

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed May 3, 2024
1 parent 48be7bf commit 2613793
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"golang.org/x/text/language"
)

// BundleCfg ...
// BundleCfg represents the configuration options for an i18n bundle.
type BundleCfg struct {
DefaultLanguage language.Tag
FormatBundleFile string
AcceptLanguage []language.Tag
RootPath string
UnmarshalFunc i18n.UnmarshalFunc
Loader Loader
DefaultLanguage language.Tag // DefaultLanguage specifies the default language for the bundle.
FormatBundleFile string // FormatBundleFile specifies the file format for the bundle.
AcceptLanguage []language.Tag // AcceptLanguage specifies the accepted languages for the bundle.
RootPath string // RootPath specifies the root path for the bundle.
UnmarshalFunc i18n.UnmarshalFunc // UnmarshalFunc specifies the function used for unmarshaling bundle files.
Loader Loader // Loader specifies the loader for loading bundle files.
}

type Loader interface {
Expand All @@ -23,7 +23,8 @@ type LoaderFunc func(path string) ([]byte, error)

func (f LoaderFunc) LoadMessage(path string) ([]byte, error) { return f(path) }

// WithBundle ...
// WithBundle returns an Option that sets the bundle configuration for GinI18n.
// If the loader is not provided in the BundleCfg, the defaultLoader will be used.
func WithBundle(config *BundleCfg) Option {
return func(g GinI18n) {
if config.Loader == nil {
Expand All @@ -33,7 +34,9 @@ func WithBundle(config *BundleCfg) Option {
}
}

// WithGetLngHandle ...
// WithGetLngHandle sets the handler function for retrieving the current language.
// The provided handler function should accept a GinI18n instance and return the current language as a string.
// This option allows you to customize how the current language is determined.
func WithGetLngHandle(handler GetLngHandler) Option {
return func(g GinI18n) {
g.setGetLngHandler(handler)
Expand Down

0 comments on commit 2613793

Please sign in to comment.