Translation Service Basic Methods
The basic methods of the translation service need to be added according to development requirements, along with the corresponding translation mappings. Currently, only translations for common MySQL errors are provided.
Open Source Libraries Used
No open source libraries are used at this time.
Service Provider
Service Identifier
"translate"
Registering the Service
P.Register("translate", func() (Depends, Resolve) {
return Depends{"config"}, func(ss ...services.Service) services.Service {
return translate.Mount(trans.All).Init(ss...)
}
})
Registration Format Refer to the Auth Service
Dependent Services
"config"
ENV Configuration
No related configuration at this time.
Service Interface Methods
type TranslateService interface {
Service // General service interface
DBError(err error) error // Translate common standard database errors
}
Usage Example
// Register 注册
func (u *User) Register() error {
result := db.Create(u)
return trans.DBError(result.Error)
}