feat: add i18n support

This commit is contained in:
firest 2022-04-19 16:48:24 +08:00
parent 0637c5bbbd
commit a7482b2fea
4 changed files with 164 additions and 18 deletions

View File

@ -0,0 +1,92 @@
emqx_slow_subs_api {
clear_records_api {
desc {
en: "Clear current data and re count slow topic."
zh: "清除当前记录,然后重新开始统计。"
}
label: {
en: "Clear Records"
zh: "清除记录"
}
}
get_records_api {
desc {
en: "Get slow topics statistics record data."
zh: "查看慢订阅的统计数据。"
}
label: {
en: "Records"
zh: "记录"
}
}
get_setting_api {
desc {
en: "Get slow subs settings."
zh: "查看配置"
}
label: {
en: "View Settings"
zh: "查看配置"
}
}
update_setting_api {
desc {
en: "Update slow subs settings."
zh: "更新配置"
}
label: {
en: "Update Settings"
zh: "更新配置"
}
}
clientid {
desc {
en: "Message clientid."
zh: "消息的客户端 ID"
}
label: {
en: "ClientID"
zh: "ClientID"
}
}
node {
desc {
en: "Message node name."
zh: "消息的节点名称"
}
label: {
en: "Node Name"
zh: "节点名"
}
}
topic {
desc {
en: "Message topic."
zh: "消息主题"
}
label: {
en: "Topic"
zh: "主题"
}
}
timespan {
desc {
en: "Timespan for message transmission."
zh: "消息的传输耗时。"
}
label: {
en: "Timespan"
zh: "传输耗时"
}
}
last_update_time {
desc {
en: "The timestamp of last update."
zh: "记录的更新时间戳。"
}
label: {
en: "Last Update Time"
zh: "更新时间"
}
}
}

View File

@ -0,0 +1,52 @@
emqx_slow_subs_schema {
enable {
desc {
en: "Enable this feature"
zh: "开启慢订阅"
}
label: {
en: "Enable"
zh: "开启"
}
}
threshold {
desc {
en: "The latency threshold for statistics."
zh: "慢订阅统计的阈值"
}
label: {
en: "Threshold"
zh: "阈值"
}
}
expire_interval {
desc {
en: "The eviction time of the record, which in the statistics record table."
zh: "慢订阅记录的有效时间"
}
label: {
en: "Eviction Time"
zh: "有效时间"
}
}
top_k_num {
desc {
en: "The maximum number of records in the slow subscription statistics record table."
zh: "慢订阅统计表的记录数量上限"
}
label: {
en: "Numbers"
zh: "记录数上限"
}
}
stats_type {
desc {
en: "The method to calculate the latency."
zh: "慢订阅的统计类型"
}
label: {
en: "Stats Type"
zh: "统计类型"
}
}
}

View File

@ -20,12 +20,13 @@
-include_lib("typerefl/include/types.hrl").
-include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-export([api_spec/0, paths/0, schema/1, fields/1, namespace/0]).
-export([slow_subs/2, get_history/0, settings/2]).
-import(hoconsc, [mk/2, ref/1]).
-import(hoconsc, [mk/2, ref/1, ref/2]).
-import(emqx_mgmt_util, [bad_request/0]).
-define(APP, emqx_slow_subs).
@ -44,17 +45,17 @@ schema(("/slow_subscriptions")) ->
'operationId' => slow_subs,
delete => #{
tags => [<<"slow subs">>],
description => <<"Clear current data and re count slow topic">>,
description => ?DESC(clear_records_api),
parameters => [],
'requestBody' => [],
responses => #{204 => <<"No Content">>}
},
get => #{
tags => [<<"slow subs">>],
description => <<"Get slow topics statistics record data">>,
description => ?DESC(get_records_api),
parameters => [
{page, mk(pos_integer(), #{in => query})},
{limit, mk(pos_integer(), #{in => query})}
ref(emqx_dashboard_swagger, page),
ref(emqx_dashboard_swagger, limit)
],
'requestBody' => [],
responses => #{200 => [{data, mk(hoconsc:array(ref(record)), #{})}]}
@ -65,12 +66,12 @@ schema("/slow_subscriptions/settings") ->
'operationId' => settings,
get => #{
tags => [<<"slow subs">>],
description => <<"Get slow subs settings">>,
description => ?DESC(get_setting_api),
responses => #{200 => conf_schema()}
},
put => #{
tags => [<<"slow subs">>],
description => <<"Update slow subs settings">>,
description => ?DESC(update_setting_api),
'requestBody' => conf_schema(),
responses => #{200 => conf_schema()}
}
@ -78,15 +79,15 @@ schema("/slow_subscriptions/settings") ->
fields(record) ->
[
{clientid, mk(string(), #{desc => <<"the clientid">>})},
{node, mk(string(), #{desc => <<"the node">>})},
{topic, mk(string(), #{desc => <<"the topic">>})},
{clientid, mk(string(), #{desc => ?DESC(clientid)})},
{node, mk(string(), #{desc => ?DESC(node)})},
{topic, mk(string(), #{desc => ?DESC(topic)})},
{timespan,
mk(
integer(),
#{desc => <<"timespan for message transmission">>}
#{desc => ?DESC(timespan)}
)},
{last_update_time, mk(integer(), #{desc => <<"the timestamp of last update">>})}
{last_update_time, mk(integer(), #{desc => ?DESC(last_update_time)})}
].
conf_schema() ->

View File

@ -1,6 +1,7 @@
-module(emqx_slow_subs_schema).
-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-export([roots/0, fields/1, desc/1, namespace/0]).
@ -10,30 +11,30 @@ roots() -> ["slow_subs"].
fields("slow_subs") ->
[
{enable, sc(boolean(), false, "Enable this feature.")},
{enable, sc(boolean(), false, enable)},
{threshold,
sc(
emqx_schema:duration_ms(),
"500ms",
"The latency threshold for statistics, the minimum value is 100ms."
threshold
)},
{expire_interval,
sc(
emqx_schema:duration_ms(),
"300s",
"The eviction time of the record, which in the statistics record table."
expire_interval
)},
{top_k_num,
sc(
pos_integer(),
10,
"The maximum number of records in the slow subscription statistics record table."
top_k_num
)},
{stats_type,
sc(
hoconsc:union([whole, internal, response]),
whole,
"The method to calculate the latency."
stats_type
)}
].
@ -46,4 +47,4 @@ desc(_) ->
%% Internal functions
%%--------------------------------------------------------------------
sc(Type, Default, Desc) ->
hoconsc:mk(Type, #{default => Default, desc => Desc}).
hoconsc:mk(Type, #{default => Default, desc => ?DESC(Desc)}).