diff --git a/compose.go b/compose.go index 6600c9b..eb7c9d4 100644 --- a/compose.go +++ b/compose.go @@ -100,7 +100,7 @@ func (s *Subject) CountString() string { if s == nil { return "1" } - return core.Sprintf("%d", s.count) + return FormatNumber(int64(s.count)) } func (s *Subject) GenderString() string { if s == nil { diff --git a/compose_test.go b/compose_test.go index e4cd0e7..ce343c0 100644 --- a/compose_test.go +++ b/compose_test.go @@ -41,6 +41,21 @@ func TestSubject_Count_Good(t *testing.T) { assert.True(t, subj.IsPlural()) } +func TestSubject_CountString_UsesLocaleFormatting(t *testing.T) { + svc, err := New() + require.NoError(t, err) + prev := Default() + SetDefault(svc) + t.Cleanup(func() { + SetDefault(prev) + }) + + require.NoError(t, SetLanguage("fr")) + + subj := S("file", "test.txt").Count(1234) + assert.Equal(t, "1 234", subj.CountString()) +} + func TestSubject_Count_Bad_NilReceiver(t *testing.T) { var s *Subject result := s.Count(5) diff --git a/context.go b/context.go index cdea823..a1ea227 100644 --- a/context.go +++ b/context.go @@ -1,7 +1,5 @@ package i18n -import "dappco.re/go/core" - // TranslationContext provides disambiguation for translations. // // T("direction.right", C("navigation")) // "rechts" (German) @@ -137,7 +135,7 @@ func (c *TranslationContext) CountString() string { if c == nil { return "1" } - return core.Sprintf("%d", c.count) + return FormatNumber(int64(c.count)) } // IsPlural reports whether the count is plural. diff --git a/context_test.go b/context_test.go index 700a051..92651c1 100644 --- a/context_test.go +++ b/context_test.go @@ -101,6 +101,21 @@ func TestTranslationContext_WithFormality_Good(t *testing.T) { } } +func TestTranslationContext_CountString_UsesLocaleFormatting(t *testing.T) { + svc, err := New() + require.NoError(t, err) + prev := Default() + SetDefault(svc) + t.Cleanup(func() { + SetDefault(prev) + }) + + require.NoError(t, SetLanguage("fr")) + + ctx := C("test").Count(1234) + assert.Equal(t, "1 234", ctx.CountString()) +} + // --- Set / Get --- func TestTranslationContext_SetGet_Good(t *testing.T) {