Internationalization
The project supports multi-language internationalization, mainly divided into front-end internationalization and back-end internationalization
Front-end internationalization
The front-end internationalization files are located in
src/locales/*, and the front-end static text translation is internationalized by the front-end
Called in vue or ts file
const { t } = useI18n();
// Usage
const name = t("sys.dictionary.dictionaryList");Backend internationalization
The internationalization files are located in the i18n folder. The backend internationalization is used to translate all dynamic data from the backend. The directory structure in core is
├── locale
│ ├── en.json
│ └── zh.json
├── translator.go
├── translator_test.go
└── var.goJust add translations in en.json and zh.json, or you can add other languages by creating corresponding JSON files like ja.json.
Initialization Method
Starting from version 1.7.7, Goctls automatically generates the following configuration.
Add the i18n configuration in the config.go file:
package config
import (
"github.com/suyuan32/simple-admin-common/config"
"github.com/suyuan32/simple-admin-common/i18n"
"github.com/suyuan32/simple-admin-common/plugins/casbin"
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
rest.RestConf
Auth rest.AuthConf
DatabaseConf config.DatabaseConf
CasbinDatabaseConf config.DatabaseConf
RedisConf config.RedisConf
CasbinConf casbin.CasbinConf
CoreRpc zrpc.RpcClientConf
CROSConf config.CROSConf
I18nConf i18n.Conf // Add this configuration
}In your xxx.yaml:
I18nConf:
Dir: # If empty, it reads files from the embedded directory. If not empty, it reads files from the specified path.trans := i18n.NewTranslator(c.I18nConf, i18n2.LocaleFS)Usage
l.svcCtx.Trans.Trans(l.ctx, "common.success")