开源软件名称(OpenSource Name):unknwon/i18n开源软件地址(OpenSource Url):https://github.com/unknwon/i18n开源编程语言(OpenSource Language):Go 99.0%开源软件介绍(OpenSource Introduction):i18nPackage i18n is for app Internationalization and Localization. IntroductionThis package provides multiple-language options to improve user experience. Sites like Go Walker and gogs.io are using this module to implement Chinese and English user interfaces. You can use following command to install this module:
UsageFirst of all, you have to import this package: import "github.com/unknwon/i18n" The format of locale files is very like INI format configuration file, which is basically key-value pairs. But this module has some improvements. Every language corresponding to a locale file, for example, suppose there are two files called The name and extensions of locale files can be anything, but we strongly recommend you to follow the style of gogsweb. Minimal exampleHere are two simplest locale file examples: File hi = hello, %s
bye = goodbye File hi = 您好,%s
bye = 再见 Do TranslationThere are two ways to do translation depends on which way is the best fit for your application or framework. Directly use package function to translate: i18n.Tr("en-US", "hi", "Unknwon")
i18n.Tr("en-US", "bye") Or create a struct and embed it: type MyController struct{
// ...other fields
i18n.Locale
}
//...
func ... {
c := &MyController{
Locale: i18n.Locale{"en-US"},
}
_ = c.Tr("hi", "Unknwon")
_ = c.Tr("bye")
} Code above will produce correspondingly:
SectionFor different pages, one key may map to different values. Therefore, i18n module also uses the section feature of INI format configuration to achieve section. For example, the key name is Content in locale file: about = About
[about]
about = About Us Get i18n.Tr("en-US", "about") Get i18n.Tr("en-US", "about.about") AmbiguityBecause dot For example, the key name is i18n.Tr("en-US", ".about.") to get expect result. Helper toolModule i18n provides a command line helper tool beei18n for simplify steps of your development. You can install it as follows:
Sync locale filesCommand
This command can operate 1 or more files in one command. More information
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论