在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):razor-1/localizer开源软件地址(OpenSource Url):https://github.com/razor-1/localizer开源编程语言(OpenSource Language):Go 100.0%开源软件介绍(OpenSource Introduction):Localizer: convenient localization for GoLocalizer intends to make it easy for you to work with locales in Go. It was inspired by many good tools that came before it, such as: I couldn't find one Go package that did everything, so I took the best of what was out there, made some improvements & tweaks, and put them together into localizer. I also wanted to leverage golang.org/x/text/language as much as possible, since it takes care of some difficult tasks. Getting Started: Examplepackage main
import (
"fmt"
"time"
"golang.org/x/text/language"
"github.com/razor-1/localizer"
"github.com/razor-1/localizer-cldr/resources/currency"
)
func main() {
l, err := localizer.NewLocale(language.Spanish)
if err != nil {
panic(err)
}
jan2020 := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
month, err := l.Calendar.Format(jan2020, "MMMM")
if err != nil {
panic(err)
}
fmt.Println(month) // "enero"
fmt.Println(l.Calendar.FormatNames.Months.Wide.Jan) // "enero"
fmt.Println(l.FmtNumber(10000.12)) // "10.000,12"
cur, err := l.FmtCurrency(currency.USD, 10000.12)
if err != nil {
panic(err)
}
fmt.Println(cur) // "10.000,12 US$"
} As you can see, the locale object makes it easy to interact with CLDR data. What about translated strings? gotl := gotext.NewLocale("translations", "es")
gotl.AddDomain("messages")
gtstore := gotextstore.GetTranslationStore(gotl)
l, err := localizer.NewLocaleWithStore(language.Spanish, gtstore)
if err != nil {
panic(err)
}
fmt.Println(l.Get("form.button.login")) //"Iniciar sesión"
fmt.Println(l.GetPlural("%d hours", 1, 1)) //"1 hora"
fmt.Println(l.GetPlural("%d hours", 2, 2)) //"2 horas" You can use any package which implements the localizer also exposes a message printer if you'd like to use it.
Just call |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论