gi18n_instance.go 847 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gi18n
  7. import "github.com/gogf/gf/container/gmap"
  8. const (
  9. // Default group name for instance usage.
  10. DefaultName = "default"
  11. )
  12. var (
  13. // instances is the instances map for management
  14. // for multiple i18n instance by name.
  15. instances = gmap.NewStrAnyMap(true)
  16. )
  17. // Instance returns an instance of Resource.
  18. // The parameter <name> is the name for the instance.
  19. func Instance(name ...string) *Manager {
  20. key := DefaultName
  21. if len(name) > 0 && name[0] != "" {
  22. key = name[0]
  23. }
  24. return instances.GetOrSetFuncLock(key, func() interface{} {
  25. return New()
  26. }).(*Manager)
  27. }