Go to file
Kailash Nadh 87a5109554 First commit. 2023-06-03 20:16:24 +05:30
LICENSE First commit. 2023-06-03 20:16:24 +05:30
README.md First commit. 2023-06-03 20:16:24 +05:30
go.mod First commit. 2023-06-03 20:16:24 +05:30
i18n.go First commit. 2023-06-03 20:16:24 +05:30
i18n_test.go First commit. 2023-06-03 20:16:24 +05:30

README.md

go-i18n

go-i18n is a tiny i18n library that enables {langKey: langValue} style JSON language maps to be loaded and used in Go programs. It is modeled after vue-i18n, optionally enabling interoperability of the same language files in Go backends a Vue frontends. It is used by listmonk and dictpress.

Usage

Sample JSON language file

A JSON language file looks is a simple map of key: value pairs. Singular/plural terms are represented as Singular|Plural. _.code and _.name are mandatory special keys. Check listmonk translations for complex examples.

{
	"_.code": "en",
	"_.name": "English",

	"pageTitle": "Welcome to the page",
	"page": "Single page|Many pages",
	"pageVars": "The page is named {name} and has {count} items"
}

	i := i18n.NewFromFile("en.json")

	i.T("pageTitle") // Welcome to the page
	i.T("page") // Single Page
	i.S("page") // Single Page
	i.P("page") // Many pages
	i.Tc("page", 1) // Single Page (second param is a number. 1 is singular)
	i.Tc("page", 2) // Many pages (>= 1 is plural)
	i.Ts("pageVars", "name", "Foo", "count", "123") // The page is named Foo and has 123 items

Licensed under the MIT license.