- getEffectiveFormality() now checks *TranslationContext for formality - Priority: TranslationContext > Subject > map["Formality"] > Service - Add tests for context formality override behavior - Update FUTURE_PROOFING.md: Context Integration now IMPLEMENTED - Update REVIEW.md: Context wiring recommendation addressed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2.4 KiB
2.4 KiB
Future-Proofing Status
This document tracks architectural decisions made to ensure the pkg/i18n package is resilient to future requirements.
Last Updated: 30 January 2026 Status: Core Complete
1. Extensibility: The "Magic Namespace" Problem
Status: ✅ IMPLEMENTED
- Solution: The
KeyHandlerinterface and middleware chain have been implemented. - Details: "Magic" keys like
i18n.label.*are now handled by specific structs inhandler.go. The coreT()method iterates through these handlers. - Benefit: New patterns can be added via
AddHandler()without modifying the core package.
2. API Design: Context & Disambiguation
Status: ✅ IMPLEMENTED
- Solution:
TranslationContextstruct andC()builder have been created incontext.go. - Details:
getEffectiveFormality()now checks*TranslationContextfor formality hints, in addition to*Subject. - Benefit: Translations can now be disambiguated via context, and formality can be set per-call without needing a Subject.
3. Storage: Interface-Driven Loading
Status: ✅ IMPLEMENTED
- Solution: The
Loaderinterface has been defined intypes.go, and the default JSON logic moved toFSLoaderinloader.go. - Details:
NewWithLoaderallows injecting any backend. - Benefit: Applications can now load translations from databases, remote APIs, or other file formats.
4. Standardization: Pluralization & CLDR
Status: ⏳ PENDING
- Current State: The package still uses a custom
pluralRulesmap intypes.go. - Recommendation: When the need arises for more languages, replace the internal
pluralRulesmap with a call togolang.org/x/text/feature/pluralor a similar standard library wrapper. The current interface hides this implementation detail, so it can be swapped later without breaking changes.
5. Data Format: Vendor Compatibility
Status: ⏳ ENABLED
- Current State: The default format is still the custom nested JSON.
- Future Path: Thanks to the
Loaderinterface, we can now implement aPoLoaderorArbLoaderto support standard translation formats used by professional vendors, without changing the core service.
Summary
The critical architectural risks (coupling, storage, and context) have been resolved. The remaining item (Pluralization standard) is an implementation detail that can be addressed incrementally without breaking the public API.