Skip to content

Commit

Permalink
feat: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lastares committed Aug 23, 2024
1 parent 37507a8 commit f10d611
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,26 @@ json 格式的配置文件内容示例

```go
type UserService struct {
// 这里省略其他注入对象
i18n *localei18n.LocaleI18N,
// 这里省略其他注入对象
i18n *localei18n.LocaleI18N,
}
func NewUserService(i18n *localei18n.LocaleI18N) *UserService {
return &UserService{
// 这里省略其他注入对象
i18n: i18n,
}
return &UserService{
// 这里省略其他注入对象
i18n: i18n,
}
}
```

4. 调用翻译函数,具体根据实际业务逻辑进行处理
```go
func (u *UserService) Store(ctx context.Context, media *model.user) (*service.User, error) {
// 其他逻辑,伪代码
// 翻译
msg := u.i18n.Tran(ctx, "user not found")
// 带变量模板的翻译
msg = u.i18n.TranWithTemplate(ctx, "user not found", map[string]any{"name": "ares"})
// 其他逻辑,伪代码
// 翻译
msg := u.i18n.Tran(ctx, "user not found")
// 带变量模板的翻译
msg = u.i18n.TranWithTemplate(ctx, "user not found", map[string]any{"name": "ares"})
}
```

Expand Down

0 comments on commit f10d611

Please sign in to comment.