diff --git a/README.md b/README.md index 18e2db8..ffb4b46 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,27 @@ # json2dart_serialization -一个网页版本的json转dart库 +[English readme](https://github.com/CaiJingLong/json2dart/blob/master/README_ENG.md) + +一个网页版本的 json 转 dart 库 + +[直接使用 json2dart](https://caijinglong.github.io/json2dart/index.html) ## 说明 -不同于https://github.com/debuggerx01/JSONFormat4Flutter 的是:这个是为了json_serializable创建的 -页面较简陋,功能完善😊 +感谢[JSONFormat4Flutter](https://github.com/debuggerx01/JSONFormat4Flutter) 给予的灵感 +不同于这个库的是:这个是为了 json_serializable 创建的 -json_serializable 可以参考flutter官网json部分 [flutter](https://flutter.io/json) +json_serializable 可以参考 flutter 官网 json 部分 [flutter](https://flutter.io/json) -项目的展示地址: https://caijinglong.github.io/json2dart/ +项目使用 dart web 开发 -项目使用dart web开发 -## 说明 -主体功能完结,有需要修改的地方欢迎留言 +主体功能已完结,有需要修改的地方欢迎留言 +## 开发环境 -``` +其他环境不保证可以编译这份代码 + +```cli dart --version Dart VM version: 2.0.0-dev.69.5 (Tue Jul 31 15:05:14 2018 +0200) on "macos_x64" ``` @@ -26,4 +31,4 @@ Dart VM version: 2.0.0-dev.69.5 (Tue Jul 31 15:05:14 2018 +0200) on "macos_x64" Created from templates made available by Stagehand under a BSD-style [license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). -the library also under BSD-style. \ No newline at end of file +the library also under BSD-style. diff --git a/README_ENG.md b/README_ENG.md new file mode 100644 index 0000000..66b0d63 --- /dev/null +++ b/README_ENG.md @@ -0,0 +1,27 @@ +# json2dart_serialization + +a dart web for json2dart + +use for web location: [json2dart](https://caijinglong.github.io/json2dart/index.html) + +## intro + +Thank you for the inspiration of this [JSONFormat4Flutter](https://github.com/debuggerx01/JSONFormat4Flutter) + +This project was created for the [json_serializable](https://pub.dartlang.org/packages/json_serializable) + +json_serializable also read the flutter's json page [flutter](https://flutter.io/json) + +## the code compile env + +```cli +dart --version +Dart VM version: 2.0.0-dev.69.5 (Tue Jul 31 15:05:14 2018 +0200) on "macos_x64" +``` + +## license + +Created from templates made available by Stagehand under a BSD-style +[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). + +the library also under BSD-style. diff --git a/lib/json_generator.dart b/lib/json_generator.dart index 846c464..e0c691c 100644 --- a/lib/json_generator.dart +++ b/lib/json_generator.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:convert'; import 'dart:html'; @@ -21,12 +22,14 @@ var downloadFileName = ""; // }"""; const defaultValue = ""; -void main() { +void main() async { + isChinese = await _isChinese(); + TextAreaElement jsonInput = querySelector("#json"); jsonInput.value = defaultValue; jsonInput.onInput.listen((event) { - print(jsonInput.value); + // print(jsonInput.value); refreshData(); }); @@ -106,7 +109,28 @@ void main() { }); } -void refreshData() { +Future _isChinese() async { + // var lang = await findSystemLocale(); + List elements = querySelectorAll("meta"); + + String lang; + for (var e in elements) { + var _lang = e.getAttribute("lang"); + if (_lang != null) { + lang = _lang; + break; + } + } + if (lang?.contains("zh") == true) { + return true; + } + + return false; +} + +bool isChinese = false; + +void refreshData() async { TextAreaElement jsonInput = querySelector("#json"); var string = jsonInput.value; String pretty; @@ -114,7 +138,11 @@ void refreshData() { try { pretty = formatJson(string); } on Exception { - result.value = "不是一个正确的json"; + if (isChinese) { + result.value = "不是一个正确的json"; + } else { + result.value = "Not JSON"; + } return; } String entityClassName; @@ -128,7 +156,15 @@ void refreshData() { var dartCode = generator.makeDartCode(); var dartFileName = ("${generator.fileName}.dart"); downloadFileName = dartFileName; - querySelector("#file_name").text = "应该使用的文件名为: $dartFileName"; + + String filePrefix; + if (isChinese) { + filePrefix = "应该使用的文件名为:"; + } else { + filePrefix = "your dart file name is:"; + } + print(filePrefix); + querySelector("#file_name").text = "$filePrefix $dartFileName"; result.value = dartCode; } diff --git a/pubspec.yaml b/pubspec.yaml index da0befb..67d8f46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,9 @@ environment: dependencies: # Your other regular dependencies here json_annotation: ^0.2.3 + intl: ^0.15.7 + dev_dependencies: build_runner: ^0.9.0 build_web_compilers: ^0.4.0 diff --git a/web/index.html b/web/index.html index c21a5e2..89b0eef 100644 --- a/web/index.html +++ b/web/index.html @@ -4,6 +4,7 @@ + @@ -14,13 +15,18 @@ -

为了便利使用json_serializable库

+
+ 中文 +
+

simple use + json_serializable +

- 将json粘贴至左边 + copy your json to left textarea
- 类名称 + dart class name jsonKey annotation @@ -32,19 +38,19 @@
- + - +
- + - - + +
diff --git a/web/index_ch.html b/web/index_ch.html new file mode 100644 index 0000000..23fc80c --- /dev/null +++ b/web/index_ch.html @@ -0,0 +1,58 @@ + + + + + + + + + + + json2dart_for_json_serializable + + + + + + +
+ English +
+

为了便利使用 + json_serializable

+
+
+ 将json粘贴至左边 + +
+ 类名称 + + + jsonKey annotation + + use camelCase +
+
+
+
+
+ + + + + + +
+
+ + + + + + + +
+
+ + + \ No newline at end of file diff --git a/web/styles.css b/web/styles.css index db367d3..cc79e52 100644 --- a/web/styles.css +++ b/web/styles.css @@ -62,7 +62,7 @@ textarea { } button { - width: 5rem; + width: 6rem; height: 2rem; font-size: 1rem; } @@ -72,3 +72,17 @@ button { padding-top: 5px; color: mediumvioletred; } + +.lang { + padding-right: 1vw; + padding-top: 1vh; + text-align: right; +} + +a { + color: blue; + text-decoration: none; +} +a:hover { + text-decoration-line: underline; +}