f827a7471c
- Removed LocaleSwitcher from NavUser, SiteHeader, and WorkbenchHeader components. - Updated tests to reflect the removal of LocaleSwitcher. - Changed default locale from "en-US" to "zh-CN" in i18n configuration. - Refactored locale resolution logic to read configured locale without relying on browser language detection. - Updated AgentDesk SDK to support language configuration from public API. - Cleaned up unused auth options fetching in the auth API.
39 lines
569 B
Go
39 lines
569 B
Go
package i18nx
|
|
|
|
type Error struct {
|
|
Key string
|
|
Args []any
|
|
Cause error
|
|
}
|
|
|
|
func Errorf(key string, args ...any) *Error {
|
|
err := &Error{Key: key, Args: args}
|
|
for _, arg := range args {
|
|
if cause, ok := arg.(error); ok {
|
|
err.Cause = cause
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
return e.Message(DefaultLocale)
|
|
}
|
|
|
|
func (e *Error) Message(locale string) string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
return Getf(locale, e.Key, e.Args...)
|
|
}
|
|
|
|
func (e *Error) Unwrap() error {
|
|
if e == nil {
|
|
return nil
|
|
}
|
|
return e.Cause
|
|
}
|