github.com/haraldrudell/parl@v0.4.176/plog/sprintf.go (about)

     1  /*
     2  © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package plog
     7  
     8  import (
     9  	"golang.org/x/text/language"
    10  	"golang.org/x/text/message"
    11  )
    12  
    13  // EnglishSprintf is like fmt.Sprintf with thousands separator
    14  var EnglishSprintf = message.NewPrinter(language.English).Sprintf
    15  
    16  // sprintf is like fmt.Sprintf and:
    17  //   - does not interpret format if a is empty, and
    18  //   - has thousands separator for numbers
    19  //   - is like parl.Sprintf but usable to packages imported by parl
    20  func Sprintf(format string, a ...any) (s string) {
    21  	if len(a) == 0 {
    22  		return format
    23  	}
    24  	return EnglishSprintf(format, a...)
    25  }