diff --git a/core_service.go b/core_service.go index dba89b7..b51ce2a 100644 --- a/core_service.go +++ b/core_service.go @@ -318,11 +318,21 @@ func (s *CoreService) IsRTL() bool { return s.svc.IsRTL() } +// RTL reports whether the wrapped service language is right-to-left. +func (s *CoreService) RTL() bool { + return s.IsRTL() +} + // CurrentIsRTL reports whether the wrapped service language is right-to-left. func (s *CoreService) CurrentIsRTL() bool { return s.IsRTL() } +// CurrentRTL reports whether the wrapped service language is right-to-left. +func (s *CoreService) CurrentRTL() bool { + return s.CurrentIsRTL() +} + // PluralCategory returns the plural category for the wrapped service language. func (s *CoreService) PluralCategory(n int) PluralCategory { return s.svc.PluralCategory(n) diff --git a/grammar.go b/grammar.go index e1a805c..daae717 100644 --- a/grammar.go +++ b/grammar.go @@ -950,6 +950,7 @@ func TemplateFuncs() template.FuncMap { "pluralForm": PluralForm, "article": ArticlePhrase, "articlePhrase": ArticlePhrase, + "definiteArticle": DefiniteArticle, "definite": DefinitePhrase, "definitePhrase": DefinitePhrase, "quote": Quote, diff --git a/grammar_test.go b/grammar_test.go index 63768a6..02e4455 100644 --- a/grammar_test.go +++ b/grammar_test.go @@ -1122,6 +1122,7 @@ func TestTemplateFuncs(t *testing.T) { "pluralForm", "article", "articlePhrase", + "definiteArticle", "definite", "definitePhrase", "quote", @@ -1170,6 +1171,20 @@ func TestTemplateFuncs_Article(t *testing.T) { if got, want := buf.String(), "an apple|the apple"; got != want { t.Fatalf("template article aliases = %q, want %q", got, want) } + + tmpl, err = template.New("").Funcs(TemplateFuncs()).Parse(`{{definiteArticle "apple"}}`) + if err != nil { + t.Fatalf("Parse() definite article helper failed: %v", err) + } + + buf.Reset() + if err := tmpl.Execute(&buf, nil); err != nil { + t.Fatalf("Execute() definite article helper failed: %v", err) + } + + if got, want := buf.String(), "the"; got != want { + t.Fatalf("template definite article = %q, want %q", got, want) + } } func TestTemplateFuncs_CompositeHelpers(t *testing.T) { diff --git a/hooks_test.go b/hooks_test.go index 189e1f6..e5f8147 100644 --- a/hooks_test.go +++ b/hooks_test.go @@ -355,6 +355,8 @@ func TestCoreService_DelegatesToWrappedService(t *testing.T) { assert.Equal(t, svc.Direction(), coreSvc.CurrentDirection()) assert.Equal(t, svc.IsRTL(), coreSvc.IsRTL()) assert.Equal(t, svc.IsRTL(), coreSvc.CurrentIsRTL()) + assert.Equal(t, svc.IsRTL(), coreSvc.RTL()) + assert.Equal(t, svc.IsRTL(), coreSvc.CurrentRTL()) assert.Equal(t, svc.PluralCategory(2), coreSvc.PluralCategory(2)) assert.Equal(t, svc.PluralCategory(2), coreSvc.CurrentPluralCategory(2)) assert.Equal(t, svc.Mode(), coreSvc.CurrentMode()) diff --git a/localise.go b/localise.go index b8afbd0..6a05593 100644 --- a/localise.go +++ b/localise.go @@ -132,6 +132,13 @@ func CurrentDirection() TextDirection { // rtl := i18n.IsRTL() func IsRTL() bool { return Direction() == DirRTL } +// RTL is a short alias for IsRTL. +// +// Example: +// +// rtl := i18n.RTL() +func RTL() bool { return IsRTL() } + // CurrentIsRTL returns true if the current default language uses // right-to-left text. // @@ -142,6 +149,15 @@ func CurrentIsRTL() bool { return defaultServiceValue(false, func(svc *Service) bool { return svc.IsRTL() }) } +// CurrentRTL is a short alias for CurrentIsRTL. +// +// Example: +// +// rtl := i18n.CurrentRTL() +func CurrentRTL() bool { + return CurrentIsRTL() +} + // CurrentPluralCategory returns the plural category for the current default language. // // Example: diff --git a/localise_test.go b/localise_test.go index 95d107b..2c225e0 100644 --- a/localise_test.go +++ b/localise_test.go @@ -232,6 +232,16 @@ func TestIsRTL_Good(t *testing.T) { assert.False(t, IsRTL(), "English should not be RTL") } +// --- Package-level RTL --- + +func TestRTL_Good(t *testing.T) { + svc, err := New() + require.NoError(t, err) + SetDefault(svc) + + assert.Equal(t, IsRTL(), RTL()) +} + // --- Package-level CurrentIsRTL --- func TestCurrentIsRTL_Good(t *testing.T) { @@ -242,6 +252,16 @@ func TestCurrentIsRTL_Good(t *testing.T) { assert.False(t, CurrentIsRTL(), "English should not be RTL") } +// --- Package-level CurrentRTL --- + +func TestCurrentRTL_Good(t *testing.T) { + svc, err := New() + require.NoError(t, err) + SetDefault(svc) + + assert.Equal(t, CurrentIsRTL(), CurrentRTL()) +} + // --- Package-level CurrentPluralCategory --- func TestCurrentPluralCategory_Good(t *testing.T) { diff --git a/service.go b/service.go index b71f9f0..16678d1 100644 --- a/service.go +++ b/service.go @@ -428,6 +428,13 @@ func (s *Service) IsRTL() bool { return s.Direction() == DirRTL } func (s *Service) CurrentIsRTL() bool { return s.IsRTL() } + +// RTL is a short alias for IsRTL. +func (s *Service) RTL() bool { return s.IsRTL() } + +// CurrentRTL is a short alias for CurrentIsRTL. +func (s *Service) CurrentRTL() bool { return s.CurrentIsRTL() } + func (s *Service) CurrentDebug() bool { return s.Debug() } diff --git a/service_test.go b/service_test.go index 6aa218b..7c85df9 100644 --- a/service_test.go +++ b/service_test.go @@ -175,6 +175,9 @@ func TestServiceCurrentStateAliases(t *testing.T) { if got, want := svc.CurrentIsRTL(), svc.IsRTL(); got != want { t.Fatalf("CurrentIsRTL() = %v, want %v", got, want) } + if got, want := svc.CurrentRTL(), svc.IsRTL(); got != want { + t.Fatalf("CurrentRTL() = %v, want %v", got, want) + } if got, want := svc.CurrentHandlers(), svc.Handlers(); len(got) != len(want) { t.Fatalf("CurrentHandlers() len = %d, want %d", len(got), len(want)) }