From a7482b2feac77a52dfa9be5bc9025c292573564d Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 19 Apr 2022 16:48:24 +0800 Subject: [PATCH 1/2] feat: add i18n support --- .../i18n/emqx_slow_subs_api_i18n.conf | 92 +++++++++++++++++++ .../i18n/emqx_slow_subs_i18n.conf | 52 +++++++++++ .../emqx_slow_subs/src/emqx_slow_subs_api.erl | 25 ++--- .../src/emqx_slow_subs_schema.erl | 13 +-- 4 files changed, 164 insertions(+), 18 deletions(-) create mode 100644 apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf create mode 100644 apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf diff --git a/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf b/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf new file mode 100644 index 000000000..52de2b921 --- /dev/null +++ b/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf @@ -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: "更新时间" + } + } +} diff --git a/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf b/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf new file mode 100644 index 000000000..b657c8d79 --- /dev/null +++ b/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf @@ -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: "统计类型" + } + } +} diff --git a/apps/emqx_slow_subs/src/emqx_slow_subs_api.erl b/apps/emqx_slow_subs/src/emqx_slow_subs_api.erl index 74adfde1c..ccd533600 100644 --- a/apps/emqx_slow_subs/src/emqx_slow_subs_api.erl +++ b/apps/emqx_slow_subs/src/emqx_slow_subs_api.erl @@ -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() -> diff --git a/apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl b/apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl index fe6a5aa0c..d570e2004 100644 --- a/apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl +++ b/apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl @@ -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)}). From 132298d30eb62d49977e09eda324aec360ba6d1e Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 19 Apr 2022 18:32:24 +0800 Subject: [PATCH 2/2] fix(slow_subs): remove redundant fields in i18n conf --- .../i18n/emqx_slow_subs_api_i18n.conf | 74 ++++++------------- .../i18n/emqx_slow_subs_i18n.conf | 34 +++------ 2 files changed, 34 insertions(+), 74 deletions(-) diff --git a/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf b/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf index 52de2b921..92862bc98 100644 --- a/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf +++ b/apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf @@ -1,92 +1,66 @@ emqx_slow_subs_api { + clear_records_api { desc { - en: "Clear current data and re count slow topic." - zh: "清除当前记录,然后重新开始统计。" - } - label: { - en: "Clear Records" - zh: "清除记录" + en: "Clear current data and re count slow topic" + zh: "清除当前记录,然后重新开始统计" } } + get_records_api { desc { - en: "Get slow topics statistics record data." - zh: "查看慢订阅的统计数据。" - } - label: { - en: "Records" - zh: "记录" + en: "View slow topics statistics record data" + zh: "查看慢订阅的统计数据" } } + get_setting_api { desc { - en: "Get slow subs settings." - zh: "查看配置" - } - label: { - en: "View Settings" + en: "View slow subs settings" zh: "查看配置" } } + update_setting_api { desc { - en: "Update slow subs settings." - zh: "更新配置" - } - label: { - en: "Update Settings" + en: "Update slow subs settings" zh: "更新配置" } } + clientid { desc { - en: "Message clientid." + en: "Message clientid" zh: "消息的客户端 ID" } - label: { - en: "ClientID" - zh: "ClientID" - } } + node { desc { - en: "Message node name." + en: "Message node name" zh: "消息的节点名称" } - label: { - en: "Node Name" - zh: "节点名" - } } + topic { desc { - en: "Message topic." - zh: "消息主题" - } - label: { - en: "Topic" - zh: "主题" + en: "Message topic" + zh: "消息的主题" } } + timespan { desc { - en: "Timespan for message transmission." - zh: "消息的传输耗时。" - } - label: { - en: "Timespan" - zh: "传输耗时" + en: "Timespan for message transmission" + zh: "消息的传输耗时" } } + last_update_time { desc { - en: "The timestamp of last update." - zh: "记录的更新时间戳。" - } - label: { - en: "Last Update Time" - zh: "更新时间" + en: "The timestamp of last update" + zh: "记录的更新时间戳" } } + } diff --git a/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf b/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf index b657c8d79..e65e802c2 100644 --- a/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf +++ b/apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf @@ -1,52 +1,38 @@ emqx_slow_subs_schema { + enable { desc { en: "Enable this feature" zh: "开启慢订阅" } - label: { - en: "Enable" - zh: "开启" - } } + threshold { desc { - en: "The latency threshold for statistics." + 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." + 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." + 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." + en: "The method to calculate the latency" zh: "慢订阅的统计类型" } - label: { - en: "Stats Type" - zh: "统计类型" - } } + }