From 22e6e1f01ac3af25f6c84bcfdd35f540f00c8f2b Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 9 Sep 2024 18:39:11 -0300 Subject: [PATCH] Add why --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 71d606e..e2237fb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,35 @@ Messages in your application are never static. They have variables, pluralization, and formatting. To work with them easily, use [ICU MessageFormat](https://unicode-org.github.io/icu/userguide/format_parse/messages/). +## Why? + +There is a great package for translations called [nicksnyder/go-i18n](/~https://github.com/nicksnyder/go-i18n). +However, once I had a lot of translations in chatbots, it started to feel cumbersome. + +So, I tried to make translations simpler. Now, instead: + +```go +localizer.Localize(&i18n.LocalizeConfig{ + DefaultMessage: &i18n.Message{ + ID: "PersonCats", + One: "{{.Name}} has {{.Count}} cat.", + Other: "{{.Name}} has {{.Count}} cats.", + }, + TemplateData: map[string]interface{}{ + "Name": "Nick", + "Count": 2, + }, + PluralCount: 2, +}) // Nick has 2 cats. +``` + +I got: + +```go +tr.Trans("person.cats", mf.Arg("name", "Nick"), mf.Arg("cats_num", 2)) +// Nick has 2 cats. +``` + ## Usage Import package