[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #118
2 changed files with 25 additions and 0 deletions
|
|
@ -88,6 +88,7 @@ var (
|
|||
var localeFS embed.FS
|
||||
|
||||
var _ Translator = (*Service)(nil)
|
||||
var _ core.Translator = (*Service)(nil)
|
||||
|
||||
// New creates a new i18n service with embedded locales.
|
||||
func New(opts ...Option) (*Service, error) {
|
||||
|
|
@ -375,6 +376,11 @@ func (s *Service) T(messageID string, args ...any) string {
|
|||
return result
|
||||
}
|
||||
|
||||
// Translate translates a message by its ID and returns a Core result.
|
||||
func (s *Service) Translate(messageID string, args ...any) core.Result {
|
||||
return core.Result{Value: s.T(messageID, args...), OK: true}
|
||||
}
|
||||
|
||||
// resolveDirect performs exact-key lookup in the current language, its base
|
||||
// language tag, and then the configured fallback language.
|
||||
func (s *Service) resolveDirect(messageID string, data any) string {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package i18n
|
|||
import (
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"dappco.re/go/core"
|
||||
)
|
||||
|
||||
type messageBaseFallbackLoader struct{}
|
||||
|
|
@ -75,6 +77,23 @@ func TestServiceT(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceTranslate(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() failed: %v", err)
|
||||
}
|
||||
|
||||
result := svc.Translate("prompt.yes")
|
||||
if !result.OK {
|
||||
t.Fatalf("Translate(prompt.yes) returned not OK: %#v", result)
|
||||
}
|
||||
if got := result.Value; got != "y" {
|
||||
t.Fatalf("Translate(prompt.yes) = %#v, want %q", got, "y")
|
||||
}
|
||||
|
||||
var _ core.Translator = (*Service)(nil)
|
||||
}
|
||||
|
||||
func TestServiceTDirectKeys(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue