2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-08-31 18:04:12 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gi18n
|
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
import "github.com/gogf/gf/v2/container/gmap"
|
2019-08-31 18:04:12 +08:00
|
|
|
|
|
|
|
const (
|
2021-05-13 00:16:45 +08:00
|
|
|
// DefaultName is the default group name for instance usage.
|
2020-12-14 13:02:08 +08:00
|
|
|
DefaultName = "default"
|
2019-08-31 18:04:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-05-10 10:56:11 +08:00
|
|
|
// instances is the instances map for management
|
|
|
|
// for multiple i18n instance by name.
|
2019-08-31 18:04:12 +08:00
|
|
|
instances = gmap.NewStrAnyMap(true)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Instance returns an instance of Resource.
|
2021-10-21 18:22:47 +08:00
|
|
|
// The parameter `name` is the name for the instance.
|
2019-09-01 00:30:01 +08:00
|
|
|
func Instance(name ...string) *Manager {
|
2020-12-14 13:02:08 +08:00
|
|
|
key := DefaultName
|
2019-08-31 18:04:12 +08:00
|
|
|
if len(name) > 0 && name[0] != "" {
|
|
|
|
key = name[0]
|
|
|
|
}
|
|
|
|
return instances.GetOrSetFuncLock(key, func() interface{} {
|
|
|
|
return New()
|
2019-09-01 00:30:01 +08:00
|
|
|
}).(*Manager)
|
2019-08-31 18:04:12 +08:00
|
|
|
}
|