🚨 Time to Say Goodbye to t (Go Translate)
I regret to inform you that this project is being deprecated. This decision was
not taken lightly, but after careful consideration, I have determined that it is
in the best interests of the community and users to move on to more up-to-date
solutions.
The main reason for this decision is that there are many excellent alternatives
available that offer more robust and comprehensive i18n
and l10n
solutions.
I hope that you will continue to support me and my future endeavors, and I
encourage you to explore the following alternatives:
t
helps you translate Go apps into multiple languages.
Features
- Configurable
- Strings with variables
- Translation folders that is relative to module
- Translation files in
yaml
format
Requirements
Getting Started
go get github.com/erdaltsksn/t
touch main.go
Directory Structure:
1 .
2 ├── translations
3 │ ├── en.yaml
4 │ └── tr.yaml
5 └── main.go
main.go:
package main
import (
"fmt"
"github.com/erdaltsksn/t"
"golang.org/x/text/language"
)
func main() {
t.Configure(t.Config{
Language: language.Turkish,
FallbackLanguage: language.English,
TranslationFolder: struct {
Path string
Relative bool
}{
Path: "/translations",
Relative: true,
},
})
fmt.Println(t.Translate("msgHello"))
fmt.Println(t.Translate("msgMorning", "Adam"))
}
en.yaml and tr.yaml:
# en.yaml
msgHello: "Hello World"
msgMorning: "Good morning, %v"
# tr.yaml
msgHello: "Merhaba Dünya"
msgMorning: "Günaydın, %v"
Output:
Merhaba Dünya
Günaydın, Adam
Installation
go get github.com/erdaltsksn/t
Updating / Upgrading
go get -u github.com/erdaltsksn/t
Usage
t.Translate("keyText")
t.Translate("keyText", "Variable")
// Print in different language
message.NewPrinter(language.Chinese).Sprintf("keyText", "Variable-1", "var-2")
Check out examples directory for more.
Contributing
If you want to contribute to this project and make it better, your help is very
welcome.
For more information, see Contributing Guide.
Security Policy
If you discover a security vulnerability within this project, please follow our
Security Policy.
Code of Conduct
This project adheres to the Contributor Covenant Code of Conduct.
By participating, you are expected to uphold this code.
Disclaimer
In no event shall we be liable to you or any third parties for any special,
punitive, incidental, indirect or consequential damages of any kind, or any
damages whatsoever, including, without limitation, those resulting from loss of
use, data or profits, and on any theory of liability, arising out of or in
connection with the use of this software.