1个不稳定发布
0.1.1 | 2022年12月24日 |
---|---|
0.1.0 |
|
#696 in 配置
46KB
944 代码行
Mulingo
一个多语言配置组件。
DDL
CREATE TABLE t_mulingo (
id VARCHAR(32) PRIMARY KEY,
owner VARCHAR(60) NOT NULL,
name_space VARCHAR(60) NOT NULL,
msg_key VARCHAR(200) NOT NULL,
lang_key VARCHAR(20) NOT NULL,
version VARCHAR(20) NOT NULL,
msg_content VARCHAR(2048) NOT NULL,
memo VARCHAR(200) NULL,
create_at TIMESTAMP NOT NULL,
update_at TIMESTAMP NOT NULL
) comment 'multi language message configuration'
用法
依赖项
mysql_async
提供运行存储函数的Conn
tracing
&tracing_subscriber
以启用跟踪和日志记录
域应用程序
域应用程序是首先需要初始化的功能入口。
use crcnt_mulingo::includes::Application;
fn create_application() {
let pool: Pool = Pool::new("mysql://<username>:<userpwd>@localhost:3306/promo");
let application = Application::new(pool);
application
}
创建Mulingo
应用程序的 create_mulingo
需要7个参数
- owner: 项目的所有者
- ns: 项目的命名空间
- lang_key: 语言键,例如:
en
,zh_CN
,... - msg_key: 项键
- msg: 项内容
- memo: 项备注,可选
use crcnt_mulingo::includes::*;
async fn create_mulingo() {
let ns: MulingoNameSpace = "com.payby.promotion".into();
let owner: MulingoOwner = "SYS_PROMOTION".into();
let lang_key: MulingoLangKey = "en".into();
let version: MulingoVersion = "0.1.2".into();
let msg_key: MulingoMsgKey = "EC_600001".into();
let msg: MulingoMsgContent = "The promotion code is overflow".into();
let memo: Option<MulingoMemo> = Some("erro code for overflow".into());
let entity = app.create_mulingo(owner,
ns,
lang_key,
msg_key,
version,
msg,
memo)
.await;
}
获取Mulingo
应用程序的 fetch_latest_mulingo
可以获取最新版本的mulingo项。
use crcnt_mulingo::includes::*;
async fn create_mulingo() {
let ns: MulingoNameSpace = "com.payby.promotion".into();
let owner: MulingoOwner = "SYS_PROMOTION".into();
let lang_key: MulingoLangKey = "en".into();
let msg_key: MulingoMsgKey = "EC_600001".into();
let mulingo = app.fetch_latest_mulingo(&owner, &ns, &msg_key, &lang_key).await;
}
依赖项
~21–36MB
~562K SLoC