From 7e827ab3ce3875b377886c7855be3dbbb5ac3d93 Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 23:56:57 +0000 Subject: [PATCH] feat(i18n): expose current formality getter Co-Authored-By: Virgil --- i18n.go | 8 ++++++++ localise_test.go | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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) { -- 2.45.3