Forráskód Böngészése

Merge pull request #7669 from lafirest/feat/chinese_desc_api_check_slow_subs

feat(slow_subs): add i18n support
lafirest 3 éve
szülő
commit
2ea539bfc3

+ 66 - 0
apps/emqx_slow_subs/i18n/emqx_slow_subs_api_i18n.conf

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

+ 38 - 0
apps/emqx_slow_subs/i18n/emqx_slow_subs_i18n.conf

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

+ 13 - 12
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() ->

+ 7 - 6
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)}).