feat(i18n): add current text direction aliases
All checks were successful
Security Scan / security (push) Successful in 14s
Test / test (push) Successful in 2m27s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 12:10:30 +00:00
parent 56099f5f07
commit 1ae9ada1fd
6 changed files with 33 additions and 0 deletions

View file

@ -318,6 +318,11 @@ func (s *CoreService) CurrentDirection() TextDirection {
return s.Direction()
}
// CurrentTextDirection is a more explicit alias for CurrentDirection.
func (s *CoreService) CurrentTextDirection() TextDirection {
return s.CurrentDirection()
}
// IsRTL reports whether the wrapped service language is right-to-left.
func (s *CoreService) IsRTL() bool {
return s.svc.IsRTL()

View file

@ -353,6 +353,7 @@ func TestCoreService_DelegatesToWrappedService(t *testing.T) {
assert.Equal(t, svc.AvailableLanguages(), coreSvc.CurrentAvailableLanguages())
assert.Equal(t, svc.Direction(), coreSvc.Direction())
assert.Equal(t, svc.Direction(), coreSvc.CurrentDirection())
assert.Equal(t, svc.Direction(), coreSvc.CurrentTextDirection())
assert.Equal(t, svc.IsRTL(), coreSvc.IsRTL())
assert.Equal(t, svc.IsRTL(), coreSvc.CurrentIsRTL())
assert.Equal(t, svc.IsRTL(), coreSvc.RTL())

View file

@ -125,6 +125,15 @@ func CurrentDirection() TextDirection {
return Direction()
}
// CurrentTextDirection is a more explicit alias for CurrentDirection.
//
// Example:
//
// dir := i18n.CurrentTextDirection()
func CurrentTextDirection() TextDirection {
return CurrentDirection()
}
// IsRTL returns true if the current language uses right-to-left text.
//
// Example:

View file

@ -222,6 +222,16 @@ func TestCurrentDirection_Good(t *testing.T) {
assert.Equal(t, DirLTR, CurrentDirection())
}
// --- Package-level CurrentTextDirection ---
func TestCurrentTextDirection_Good(t *testing.T) {
svc, err := New()
require.NoError(t, err)
SetDefault(svc)
assert.Equal(t, CurrentDirection(), CurrentTextDirection())
}
// --- Package-level IsRTL ---
func TestIsRTL_Good(t *testing.T) {

View file

@ -424,6 +424,11 @@ func (s *Service) CurrentDirection() TextDirection {
return s.Direction()
}
// CurrentTextDirection is a more explicit alias for CurrentDirection.
func (s *Service) CurrentTextDirection() TextDirection {
return s.CurrentDirection()
}
func (s *Service) IsRTL() bool { return s.Direction() == DirRTL }
func (s *Service) CurrentIsRTL() bool {
return s.IsRTL()

View file

@ -169,6 +169,9 @@ func TestServiceCurrentStateAliases(t *testing.T) {
if got, want := svc.CurrentDirection(), svc.Direction(); got != want {
t.Fatalf("CurrentDirection() = %v, want %v", got, want)
}
if got, want := svc.CurrentTextDirection(), svc.CurrentDirection(); got != want {
t.Fatalf("CurrentTextDirection() = %v, want %v", got, want)
}
if got, want := svc.CurrentPluralCategory(2), svc.PluralCategory(2); got != want {
t.Fatalf("CurrentPluralCategory() = %v, want %v", got, want)
}