[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #107
2 changed files with 19 additions and 0 deletions
17
i18n.go
17
i18n.go
|
|
@ -2,6 +2,7 @@ package i18n
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"dappco.re/go/core"
|
||||
|
|
@ -92,6 +93,7 @@ func N(format string, value any) string {
|
|||
// Prompt("yes") // "y"
|
||||
// Prompt("confirm") // "Are you sure?"
|
||||
func Prompt(key string) string {
|
||||
key = normalizeLookupKey(key)
|
||||
if key == "" {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -102,12 +104,27 @@ func Prompt(key string) string {
|
|||
//
|
||||
// Lang("de") // "German"
|
||||
func Lang(key string) string {
|
||||
key = normalizeLookupKey(key)
|
||||
if key == "" {
|
||||
return ""
|
||||
}
|
||||
if got := T("lang." + key); got != "lang."+key {
|
||||
return got
|
||||
}
|
||||
if idx := strings.IndexAny(key, "-_"); idx > 0 {
|
||||
if base := key[:idx]; base != "" {
|
||||
if got := T("lang." + base); got != "lang."+base {
|
||||
return got
|
||||
}
|
||||
}
|
||||
}
|
||||
return T("lang." + key)
|
||||
}
|
||||
|
||||
func normalizeLookupKey(key string) string {
|
||||
return core.Lower(core.Trim(key))
|
||||
}
|
||||
|
||||
// AddHandler appends one or more handlers to the default service's handler chain.
|
||||
func AddHandler(handlers ...KeyHandler) {
|
||||
if svc := Default(); svc != nil {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ func TestPrompt_Good(t *testing.T) {
|
|||
want string
|
||||
}{
|
||||
{"yes", "yes", "y"},
|
||||
{"yes_trimmed", " yes ", "y"},
|
||||
{"confirm", "confirm", "Are you sure?"},
|
||||
{"empty", "", ""},
|
||||
}
|
||||
|
|
@ -197,6 +198,7 @@ func TestLang_Good(t *testing.T) {
|
|||
}{
|
||||
{"de", "de", "German"},
|
||||
{"fr", "fr", "French"},
|
||||
{"fr_ca", "fr_CA", "French"},
|
||||
{"empty", "", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue