https://github.com/go-i18n/i18n
Package i18n provides internationalization and localization for your Go applications
https://github.com/go-i18n/i18n
cldr go i18n internationalization l10n localization lsif-enabled pluralization
Last synced: about 2 months ago
JSON representation
Package i18n provides internationalization and localization for your Go applications
- Host: GitHub
- URL: https://github.com/go-i18n/i18n
- Owner: go-i18n
- License: mit
- Created: 2021-09-01T16:23:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-10T15:29:38.000Z (about 3 years ago)
- Last Synced: 2024-12-23T07:23:01.247Z (4 months ago)
- Topics: cldr, go, i18n, internationalization, l10n, localization, lsif-enabled, pluralization
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 51
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# i18n
[](https://github.com/go-i18n/i18n/actions?query=branch%3Amain)
[](https://codecov.io/gh/go-i18n/i18n)
[](https://pkg.go.dev/github.com/go-i18n/i18n?tab=doc)
[](https://sourcegraph.com/github.com/go-i18n/i18n)Package i18n provides internationalization and localization for your Go applications.
## Installation
The minimum requirement of Go is **1.16**.
go get unknwon.dev/i18n
## Getting started
```ini
# locale_en-US.ini
[plurals]
file.one = file
file.other = filesdog.one = dog
dog.other = dogs[messages]
test1 = This patch has %[1]d changed ${file, 1} and deleted %[2]d ${file, 2}
test2 = I have %[1]d ${dog, 1}
``````ini
# locale_zh-CN.ini
[plurals]
file.other = 文件[messages]
test1 = 该补丁变更了 %[1]d 个${file, 1}并删除了 %[2]d 个${file, 2}
``````go
package mainimport (
"fmt""unknwon.dev/i18n"
)func main() {
s := i18n.NewStore()
l1, err := s.AddLocale("en-US", "English", "locale_en-US.ini")
// ... handler errorl2, err := s.AddLocale("zh-CN", "简体中文", "locale_zh-CN.ini")
// ... handler errorfmt.Println(l1.Translate("messages::test1", 1, 2))
// => "This patch has 1 changed file and deleted 2 files"fmt.Println(l2.Translate("messages::test1", 1, 2))
// => "该补丁变更了 1 个文件并删除了 2 个文件"fmt.Println(l2.TranslateWithFallback(l1, "messages::test2", 1))
// => "I have 1 dog"
}
```## License
This project is under the MIT License. See the [LICENSE](LICENSE) file for the full license text.