diff --git a/i18n.go b/i18n.go index ba7bff6..a045223 100644 --- a/i18n.go +++ b/i18n.go @@ -61,6 +61,14 @@ func CurrentMode() Mode { return ModeNormal } +// CurrentFormality returns the current default formality. +func CurrentFormality() Formality { + if svc := Default(); svc != nil { + return svc.Formality() + } + return FormalityNeutral +} + // N formats a number using the i18n.numeric.* namespace. // // N("number", 1234567) // "1,234,567" diff --git a/localise_test.go b/localise_test.go index 9f6157b..ff5fe72 100644 --- a/localise_test.go +++ b/localise_test.go @@ -95,7 +95,7 @@ func TestIsRTLLanguage_Good(t *testing.T) { {"german", "de", false}, {"french", "fr", false}, {"unknown", "xx", false}, - {"arabic_variant", "ar-EG-extra", true}, // len > 2 prefix check + {"arabic_variant", "ar-EG-extra", true}, // len > 2 prefix check {"english_variant", "en-US-extra", false}, // len > 2, not RTL } for _, tt := range tests { @@ -119,6 +119,19 @@ func TestSetFormality_Good(t *testing.T) { assert.Equal(t, FormalityNeutral, svc.Formality()) } +// --- Package-level CurrentFormality --- + +func TestCurrentFormality_Good(t *testing.T) { + svc, err := New() + require.NoError(t, err) + SetDefault(svc) + + assert.Equal(t, FormalityNeutral, CurrentFormality()) + + SetFormality(FormalityFormal) + assert.Equal(t, FormalityFormal, CurrentFormality()) +} + // --- Package-level Direction --- func TestDirection_Good(t *testing.T) {