You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.1 KiB

  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package message
  5. // TODO: some types in this file will need to be made public at some time.
  6. // Documentation and method names will reflect this by using the exported name.
  7. import (
  8. "golang.org/x/text/language"
  9. "golang.org/x/text/message/catalog"
  10. )
  11. // MatchLanguage reports the matched tag obtained from language.MatchStrings for
  12. // the Matcher of the DefaultCatalog.
  13. func MatchLanguage(preferred ...string) language.Tag {
  14. c := DefaultCatalog
  15. tag, _ := language.MatchStrings(c.Matcher(), preferred...)
  16. return tag
  17. }
  18. // DefaultCatalog is used by SetString.
  19. var DefaultCatalog catalog.Catalog = defaultCatalog
  20. var defaultCatalog = catalog.NewBuilder()
  21. // SetString calls SetString on the initial default Catalog.
  22. func SetString(tag language.Tag, key string, msg string) error {
  23. return defaultCatalog.SetString(tag, key, msg)
  24. }
  25. // Set calls Set on the initial default Catalog.
  26. func Set(tag language.Tag, key string, msg ...catalog.Message) error {
  27. return defaultCatalog.Set(tag, key, msg...)
  28. }