Skip to content

Commit 149b01b

Browse files
committed
add chinese、english和german
1 parent a52cca1 commit 149b01b

File tree

22 files changed

+417
-148
lines changed

22 files changed

+417
-148
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@
156156
<artifactId>svm</artifactId>
157157
<version>${graalvm-svm.version}</version>
158158
</dependency>
159+
<dependency>
160+
<groupId>org.mapdb</groupId>
161+
<artifactId>mapdb</artifactId>
162+
<version>${mapdb.version}</version>
163+
</dependency>
159164
</dependencies>
160165
</dependencyManagement>
161166

toolkit-app/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,21 @@
6060
<groupId>org.graalvm.nativeimage</groupId>
6161
<artifactId>svm</artifactId>
6262
</dependency>
63+
<dependency>
64+
<groupId>net.jpountz.lz4</groupId>
65+
<artifactId>lz4</artifactId>
66+
<version>1.3.0</version>
67+
</dependency>
6368
</dependencies>
6469

6570
<build>
71+
<sourceDirectory>src/main/java</sourceDirectory>
72+
<resources>
73+
<resource>
74+
<directory>src/main/resources</directory>
75+
</resource>
76+
</resources>
77+
6678
<!-- detect OS classifier, needed for distribution Zip file -->
6779
<extensions>
6880
<extension>

toolkit-app/src/main/java/iot/technology/client/toolkit/app/ToolKitCommand.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
import iot.technology.client.toolkit.app.config.LogLevelConfig;
1919
import iot.technology.client.toolkit.app.settings.ConfigCommand;
20+
import iot.technology.client.toolkit.app.settings.lang.LangService;
2021
import iot.technology.client.toolkit.coap.command.CoapCommand;
2122
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
2223
import iot.technology.client.toolkit.common.constants.HelpVersionGroup;
24+
import iot.technology.client.toolkit.common.constants.StorageConstants;
2325
import iot.technology.client.toolkit.common.exception.ExceptionMessageHandler;
2426
import iot.technology.client.toolkit.mqtt.command.MqttCommand;
2527
import org.fusesource.jansi.AnsiConsole;
@@ -56,15 +58,18 @@ public class ToolKitCommand implements Callable<Integer> {
5658
@CommandLine.ArgGroup
5759
HelpVersionGroup helpVersionGroup;
5860

59-
ResourceBundle bundle = ResourceBundle.getBundle("i18n.messages");
61+
ResourceBundle bundle = ResourceBundle.getBundle(StorageConstants.LANG_MESSAGES);
62+
6063

6164
public static void main(String[] args) {
6265
LogLevelConfig.setLogLevel();
6366
AnsiConsole.systemInstall();
6467
try {
65-
Locale.setDefault(new Locale("zh"));
66-
68+
String locale = LangService.currentLocale();
69+
Locale.setDefault(new Locale(locale));
70+
ResourceBundle bundle = ResourceBundle.getBundle(StorageConstants.LANG_MESSAGES);
6771
CommandLine commandLine = new CommandLine(new ToolKitCommand())
72+
.setResourceBundle(bundle)
6873
.setExecutionExceptionHandler(new ExceptionMessageHandler())
6974
.setAdjustLineBreaksForWideCJKCharacters(true)
7075
.setCaseInsensitiveEnumValuesAllowed(true);
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package iot.technology.client.toolkit.app.settings;
22

3-
import iot.technology.client.toolkit.app.settings.lang.LanguageCommand;
3+
import iot.technology.client.toolkit.app.settings.lang.LangService;
44
import iot.technology.client.toolkit.common.constants.ExitCodeEnum;
5+
import iot.technology.client.toolkit.common.constants.HelpVersionGroup;
6+
import iot.technology.client.toolkit.common.constants.LangEnum;
7+
import iot.technology.client.toolkit.common.constants.StorageConstants;
58
import picocli.CommandLine;
69

10+
import java.util.Arrays;
11+
import java.util.ResourceBundle;
712
import java.util.concurrent.Callable;
813

914
/**
@@ -15,18 +20,32 @@
1520
optionListHeading = "%n${bundle:general.option}:%n",
1621
header = "@|fg(blue),bold ${bundle:config.header}|@",
1722
description = "@|fg(blue),italic ${bundle:config.description}|@",
18-
mixinStandardHelpOptions = true,
19-
subcommands = {
20-
LanguageCommand.class
21-
},
2223
footerHeading = "%nCopyright (c) 2019-2022, ${bundle:general.copyright}",
2324
footer = "%nDeveloped by mushuwei",
2425
versionProvider = iot.technology.client.toolkit.common.constants.VersionInfo.class
2526
)
2627
public class ConfigCommand implements Callable<Integer> {
2728

29+
ResourceBundle bundle = ResourceBundle.getBundle(StorageConstants.LANG_MESSAGES);
30+
31+
@CommandLine.ArgGroup
32+
HelpVersionGroup helpVersionGroup;
33+
34+
@CommandLine.Option(
35+
names = {"-l", "--locale"},
36+
defaultValue = "en",
37+
required = true,
38+
showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
39+
description = "${bundle:config.locale}")
40+
private String locale;
41+
2842
@Override
2943
public Integer call() throws Exception {
44+
boolean isMatch = Arrays.stream(LangEnum.values()).anyMatch(ls -> ls.getValue().equals(locale));
45+
if (!isMatch) {
46+
throw new RuntimeException(bundle.getString("config.locale.miss"));
47+
}
48+
LangService.updateLocale(locale);
3049
return ExitCodeEnum.SUCCESS.getValue();
3150
}
3251
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package iot.technology.client.toolkit.app.settings.lang;
2+
3+
import iot.technology.client.toolkit.common.constants.LangEnum;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.nio.charset.StandardCharsets;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.Optional;
12+
13+
/**
14+
* @author mushuwei
15+
*/
16+
public class LangService {
17+
18+
public static final String userHome = System.getProperty("user.home");
19+
20+
private static final String FILE_NAME = userHome + File.separator + ".toolkit" + File.separator + "config" + File.separator + "lang";
21+
22+
23+
public static void updateLocale(String locale) {
24+
try {
25+
File file = new File(FILE_NAME);
26+
String ls = "locale=" + locale;
27+
Path path = Paths.get(FILE_NAME);
28+
if (!file.exists()) {
29+
File fileParent = file.getParentFile();
30+
if (!fileParent.exists()) {
31+
fileParent.mkdirs();
32+
}
33+
if (!file.exists()) {
34+
file.createNewFile();
35+
Files.write(path, ls.getBytes(StandardCharsets.UTF_8));
36+
}
37+
}
38+
Files.write(path, ls.getBytes(StandardCharsets.UTF_8));
39+
} catch (IOException e) {
40+
throw new RuntimeException(e);
41+
}
42+
}
43+
44+
public static String currentLocale() {
45+
File file = new File(FILE_NAME);
46+
if (file.exists()) {
47+
try {
48+
Path path = Paths.get(FILE_NAME);
49+
Optional<String> optional = Files.lines(path).filter(str -> str.contains("locale")).findFirst();
50+
if (optional.isPresent()) {
51+
String ls = optional.get();
52+
int equalIndex = ls.indexOf("=");
53+
String locale = ls.substring(equalIndex + 1);
54+
return locale;
55+
}
56+
Files.write(path, "locale=en".getBytes(StandardCharsets.UTF_8));
57+
return LangEnum.EN.getValue();
58+
} catch (IOException e) {
59+
throw new RuntimeException(e);
60+
}
61+
}
62+
noExistAndCreateFile();
63+
return LangEnum.EN.getValue();
64+
}
65+
66+
public static void noExistAndCreateFile() {
67+
try {
68+
File file = new File(FILE_NAME);
69+
if (!file.exists()) {
70+
File fileParent = file.getParentFile();
71+
if (!fileParent.exists()) {
72+
fileParent.mkdirs();
73+
}
74+
if (!file.exists()) {
75+
file.createNewFile();
76+
Files.write(Paths.get(FILE_NAME), "locale=en".getBytes(StandardCharsets.UTF_8));
77+
}
78+
}
79+
} catch (IOException e) {
80+
throw new RuntimeException(e);
81+
}
82+
}
83+
}

toolkit-app/src/main/java/iot/technology/client/toolkit/app/settings/lang/LanguageCommand.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

toolkit-app/src/main/resources/i18n/messages.properties

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,44 @@ config.header= general configuration
1111
config.description= Toolkit general configuration operation.
1212
config.lang.header= language configuration
1313
config.lang.description= Toolkit language configuration.
14+
config.locale=support zh=chinese; de=german; en=english
15+
config.locale.miss=Missing locale! Either `zh` or `en` or `de` is required.
1416

1517
#Coap settings
1618
coap.header= CoAP Client Toolkit
19+
coap.response=Response
20+
coap.payload=Payload
21+
coap.request.payload.description=POST message payload
22+
coap.request.format.description=Payload content-type
1723
coap.description= user-friendly CoAP protocol client toolkit
24+
coap.uri.description= URI of the server to connect to
25+
coap.accept.description= accepted response content-type
26+
coap.get.description= Request data from CoAP Resource
27+
coap.desc.description=introduction and description of CoAP protocol
28+
coap.disc.description=list available resources
29+
coap.available.resources= Available Resources
30+
coap.del.description= Delete CoAP Resource
31+
coap.media.types.description=List supported MIME types
32+
coap.media.types=Coap Supported Media Types
33+
coap.post.description=Create/Update data in CoAP Resource
34+
coap.put.description=Update data in CoAP Resource
35+
36+
1837

1938
#MQTT settings
2039
mqtt.header = MQTT Client Toolkit
21-
mqtt.description= user-friendly MQTT protocol client toolkit
40+
mqtt.description= user-friendly MQTT protocol client toolkit
41+
mqtt.sub.description=subscribe for updates from the broker
42+
mqtt.pub.description=publish a message to the broker
43+
mqtt.desc.description=introduction and description of MQTT protocol
44+
mqtt.broker.desc=the broker host
45+
mqtt.port.desc=the broker port
46+
mqtt.client.id.desc=the client id
47+
mqtt.username.desc=the username
48+
mqtt.password.desc=the password
49+
mqtt.qos.desc=the QoS of the message, 0/1/2
50+
mqtt.topic.desc=the message topic
51+
mqtt.keepalive.desc=send a ping every SEC seconds
52+
mqtt.message.desc=the message body
53+
mqtt.failed.connect=Failed to connect to MQTT broker at
54+
mqtt.result.code=Result code is:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#genaral
2+
general.option= Optionen sind
3+
general.header= IoT Client Toolkit CLI
4+
general.description= Ein praktisches Toolkit für IoT-Entwickler und Lernende.
5+
general.copyright= IoT-Technologie
6+
general.version.description= Diese Hilfenachricht anzeigen und beenden.
7+
general.help.description= Versionsinformationen drucken und beenden.
8+
9+
#config.settings
10+
config.header= allgemeine Konfiguration
11+
config.description= Toolkit allgemeine Konfigurationsoperation.
12+
config.lang.header= Sprachkonfiguration
13+
config.lang.description= Toolkit Sprachkonfiguration.
14+
config.locale=Unterstützung zh=Chinesisch; de=deutsch; en=english
15+
config.locale.miss=Mangelnde sprache! zh Oder en Oder de ist erforderlich
16+
17+
#Coap settings
18+
coap.header= CoAP Client Toolkit
19+
coap.response=Antwort
20+
coap.payload=Nutzlast
21+
coap.request.payload.description=Nutzlast der POST-Nachricht
22+
coap.request.format.description=Payload-Inhaltstyp
23+
coap.description= benutzerfreundliches CoAP Protokoll Client Toolkit
24+
coap.uri.description= URI des Servers, zu dem eine Verbindung hergestellt werden soll
25+
coap.accept.description= Akzeptierter Inhaltstyp der Antwort
26+
coap.get.description= Fordern Sie Daten von der CoAP Ressource an
27+
coap.desc.description=Einführung und Beschreibung des CoAP Protokolls
28+
coap.disc.description=verfügbare Ressourcen auflisten
29+
coap.available.resources= Verfügbare Ressourcen
30+
coap.del.description=CoAP Ressource löschen
31+
coap.media.types.description=Unterstützte MIME-Typen auflisten
32+
coap.media.types=Von Coap unterstützte Medientypen
33+
coap.post.description=Daten in CoAP-Ressource erstellen/aktualisieren
34+
coap.put.description=Aktualisieren Sie die Daten in der CoAP Ressource
35+
36+
37+
38+
#MQTT settings
39+
mqtt.header = MQTT Client Toolkit
40+
mqtt.description= benutzerfreundliches MQTT Protokoll Client Toolkit
41+
mqtt.sub.description=Abonnieren Sie Updates vom Broker
42+
mqtt.pub.description=Veröffentlichen Sie eine Nachricht an den Broker
43+
mqtt.desc.description=Einführung und Beschreibung des MQTT Protokolls
44+
mqtt.broker.desc=der broker host
45+
mqtt.port.desc=der broker port
46+
mqtt.client.id.desc=die client id
47+
mqtt.username.desc=Nutzername
48+
mqtt.password.desc=Passwort
49+
mqtt.qos.desc=Nachrichtenqualität des Servicelevels, 0/1/2
50+
mqtt.topic.desc=das Nachrichtenthema
51+
mqtt.keepalive.desc=Senden Sie alle SEC Sekunden einen Ping
52+
mqtt.message.desc=der Nachrichtentext
53+
mqtt.failed.connect=Fehler beim Herstellen einer Verbindung zum MQTT Broker unter
54+
mqtt.result.code=Ergebniscode ist:

toolkit-app/src/main/resources/i18n/messages_zh.properties

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,42 @@ config.header= 通用配置
1212
config.description = Toolkit 通用配置操作.
1313
config.lang.header= 语言配置
1414
config.lang.description= Toolkit 语言配置.
15+
config.locale=支持zh=中文; de=德语; en=英语
16+
config.locale.miss=缺少语言环境! zh 或 en 或 de是必需的
1517

1618
#Coap settings
1719
coap.header= CoAP 客户端工具包
20+
coap.response=响应
21+
coap.payload=负载内容
22+
coap.request.payload.description=发送消息有效负载
23+
coap.request.format.description=消息负载内容类型
1824
coap.description= 用户友好的CoAP协议客户端工具包
25+
coap.uri.description= 连接的服务器URI
26+
coap.accept.description= 接受响应内容类型
27+
coap.get.description= 从CoAP资源请求资源
28+
coap.desc.description= CoAP协议的介绍和描述
29+
coap.disc.description= 列出可用的资源
30+
coap.available.resources= 可用的资源
31+
coap.del.description=删除CoAP资源
32+
coap.media.types.description=支持的媒体类型列表
33+
coap.media.types=Coap支持的媒体类型
34+
coap.post.description=创建/更新CoAP资源中的数据
35+
coap.put.description=更新CoAP资源中的数据
1936

2037
#MQTT settings
2138
mqtt.header = MQTT 客户端工具包
22-
mqtt.description= 用户友好的MQTT协议客户端工具包
39+
mqtt.description= 用户友好的MQTT协议客户端工具包
40+
mqtt.sub.description=从MQTT Broker(代理)订阅更新
41+
mqtt.pub.description=向代理发布消息
42+
mqtt.desc.description=MQTT协议的介绍和描述
43+
mqtt.broker.desc=MQTT Broker(代理)网络地址
44+
mqtt.port.desc=MQTT Broker(代理)网络端口
45+
mqtt.client.id.desc=设备编号
46+
mqtt.username.desc=用户名
47+
mqtt.password.desc=密码
48+
mqtt.qos.desc=消息服务质量级别, 0/1/2
49+
mqtt.topic.desc=消息主题
50+
mqtt.keepalive.desc=多少秒钟发送一个ping报文
51+
mqtt.message.desc=消息负载内容
52+
mqtt.failed.connect=连接到MQTT Broker(代理)失败
53+
mqtt.result.code=错误码:

0 commit comments

Comments
 (0)