├── .github └── workflows │ └── lint.yml ├── .gitignore ├── README.md ├── melos.yaml ├── packages ├── translation_engine_baidu │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_baidu.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_baidu_test.dart ├── translation_engine_caiyun │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_caiyun.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_caiyun_test.dart ├── translation_engine_deepl │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_deepl.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_deepl_test.dart ├── translation_engine_google │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_google.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_google_test.dart ├── translation_engine_ibmwatson │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_ibmwatson.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_ibmwatson_test.dart ├── translation_engine_iciba │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_iciba.dart │ ├── pubspec.yaml │ └── test │ │ └── translate_engine_iciba_test.dart ├── translation_engine_openai │ ├── .gitignore │ ├── .metadata │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_openai.dart │ └── pubspec.yaml ├── translation_engine_tencent │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ └── translation_engine_tencent.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_tencent_test.dart ├── translation_engine_youdao │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ ├── translation_engine_youdao.dart │ │ └── youdao_api_known_errors.dart │ ├── pubspec.yaml │ └── test │ │ └── translation_engine_youdao_test.dart ├── uni_translate │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── lib │ │ ├── src │ │ │ └── uni_translate.dart │ │ └── uni_translate.dart │ ├── pubspec.yaml │ └── test │ │ └── uni_translate_test.dart └── uni_translate_client │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── analysis_options.yaml │ ├── build.yaml │ ├── lib │ ├── src │ │ ├── detect_language_request.dart │ │ ├── detect_language_request.g.dart │ │ ├── detect_language_response.dart │ │ ├── detect_language_response.g.dart │ │ ├── look_up_request.dart │ │ ├── look_up_request.g.dart │ │ ├── look_up_response.dart │ │ ├── look_up_response.g.dart │ │ ├── models │ │ │ ├── language_pair.dart │ │ │ ├── language_pair.g.dart │ │ │ ├── text_detection.dart │ │ │ ├── text_detection.g.dart │ │ │ ├── text_translation.dart │ │ │ ├── text_translation.g.dart │ │ │ ├── word_definition.dart │ │ │ ├── word_definition.g.dart │ │ │ ├── word_image.dart │ │ │ ├── word_image.g.dart │ │ │ ├── word_phrase.dart │ │ │ ├── word_phrase.g.dart │ │ │ ├── word_pronunciation.dart │ │ │ ├── word_pronunciation.g.dart │ │ │ ├── word_sentence.dart │ │ │ ├── word_sentence.g.dart │ │ │ ├── word_tag.dart │ │ │ ├── word_tag.g.dart │ │ │ ├── word_tense.dart │ │ │ └── word_tense.g.dart │ │ ├── translate_request.dart │ │ ├── translate_request.g.dart │ │ ├── translate_response.dart │ │ ├── translate_response.g.dart │ │ ├── translation_engine.dart │ │ ├── translation_engine_scope.dart │ │ ├── uni_translate_client.dart │ │ ├── uni_translate_client_adapter.dart │ │ ├── uni_translate_client_error.dart │ │ └── uni_translate_client_error.g.dart │ └── uni_translate_client.dart │ ├── pubspec.yaml │ └── test │ └── uni_translate_client_test.dart └── pubspec.yaml /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | analyze: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: subosito/flutter-action@v2 15 | with: 16 | flutter-version: "3.22.0" 17 | channel: "stable" 18 | - uses: bluefireteam/melos-action@v2 19 | - run: melos run analyze 20 | 21 | format: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v3 25 | - uses: subosito/flutter-action@v2 26 | with: 27 | flutter-version: "3.22.0" 28 | channel: "stable" 29 | cache: true 30 | - uses: bluefireteam/melos-action@v2 31 | - run: melos run format-check 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .dart_tool/ 2 | .idea/ 3 | *.iml 4 | 5 | **/pubspec_overrides.yaml 6 | pubspec.lock -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # uni_translate 2 | 3 | [![pub version][pub-image]][pub-url] [![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos) ![][visits-count-image] 4 | 5 | [pub-image]: https://img.shields.io/pub/v/uni_translate.svg?style=flat-square 6 | [pub-url]: https://pub.dev/packages/uni_translate 7 | 8 | [visits-count-image]: https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/biyidev.uni_translate/visits 9 | 10 | A universal translate client. 11 | 12 | ## Engines 13 | 14 | These are the available engines in this repository. 15 | 16 | | Package | Description | 17 | | ------------------------------------------------------------------------ | ----------- | 18 | | [translation_engine_baidu](./packages/translation_engine_baidu/) | - | 19 | | [translation_engine_caiyun](./packages/translation_engine_caiyun/) | - | 20 | | [translation_engine_deepl](./packages/translation_engine_deepl/) | - | 21 | | [translation_engine_google](./packages/translation_engine_google/) | - | 22 | | [translation_engine_ibmwatson](./packages/translation_engine_ibmwatson/) | - | 23 | | [translation_engine_iciba](./packages/translation_engine_iciba/) | - | 24 | | [translation_engine_sogou](./packages/translation_engine_sogou/) | - | 25 | | [translation_engine_tencent](./packages/translation_engine_tencent/) | - | 26 | | [translation_engine_youdao](./packages/translation_engine_youdao/) | - | 27 | -------------------------------------------------------------------------------- /melos.yaml: -------------------------------------------------------------------------------- 1 | name: uni_translate_workspace 2 | 3 | packages: 4 | - packages/** 5 | 6 | scripts: 7 | analyze: 8 | run: | 9 | melos exec -c 10 -- \ 10 | flutter analyze --fatal-infos 11 | description: Run `flutter analyze` for all packages. 12 | 13 | format: 14 | exec: dart format . --fix 15 | description: Run `dart format` for all packages. 16 | 17 | format-check: 18 | exec: dart format . --fix --set-exit-if-changed 19 | description: Run `dart format` checks for all packages. 20 | 21 | fix: 22 | exec: dart fix . --apply 23 | description: Run `dart fix` for all packages. 24 | 25 | test: 26 | exec: flutter test 27 | description: Run `flutter test` for all packages. 28 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_baidu 2 | 3 | Baidu translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_baidu.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_baidu 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | 14 | ## Related Links 15 | 16 | - https://fanyi-api.baidu.com/product/11 17 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/lib/translation_engine_baidu.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_baidu; 2 | 3 | import 'dart:convert'; 4 | import 'dart:math'; 5 | 6 | import 'package:crypto/crypto.dart'; 7 | import 'package:http/http.dart' as http; 8 | import 'package:uni_translate_client/uni_translate_client.dart'; 9 | 10 | const String kEngineTypeBaidu = 'baidu'; 11 | 12 | const String _kEngineOptionKeyAppId = 'appId'; 13 | const String _kEngineOptionKeyAppKey = 'appKey'; 14 | 15 | String _md5(String data) { 16 | return md5.convert(utf8.encode(data)).toString(); 17 | } 18 | 19 | class BaiduTranslationEngine extends TranslationEngine { 20 | BaiduTranslationEngine({ 21 | required super.identifier, 22 | super.option, 23 | }); 24 | 25 | static List optionKeys = [ 26 | _kEngineOptionKeyAppId, 27 | _kEngineOptionKeyAppKey, 28 | ]; 29 | 30 | @override 31 | String get type => kEngineTypeBaidu; 32 | 33 | @override 34 | List get supportedScopes { 35 | return [ 36 | TranslationEngineScope.detectLanguage, 37 | TranslationEngineScope.translate, 38 | ]; 39 | } 40 | 41 | String get _optionAppId => option?[_kEngineOptionKeyAppId] ?? ''; 42 | String get _optionAppKey => option?[_kEngineOptionKeyAppKey] ?? ''; 43 | 44 | String? _convertLanguageCode(String? languageCode) { 45 | Map map = { 46 | // 'de': 'de', 47 | // 'en': 'en', 48 | 'es': 'spa', 49 | 'fr': 'fra', 50 | // 'it': 'it', 51 | 'ja': 'jp', 52 | 'ko': 'kor', 53 | // 'pt': 'pt', 54 | 'ru': 'ru', 55 | // 'zh': 'zh', 56 | }; 57 | 58 | if (map.containsKey(languageCode)) { 59 | return map[languageCode]; 60 | } 61 | return languageCode; 62 | } 63 | 64 | @override 65 | Future detectLanguage( 66 | DetectLanguageRequest request, 67 | ) async { 68 | List detections = []; 69 | 70 | String q = request.texts.first; 71 | 72 | final salt = Random().nextInt(999999); 73 | final sign = _md5('$_optionAppId$q$salt$_optionAppKey'); 74 | 75 | Uri uri = Uri.https( 76 | 'fanyi-api.baidu.com', 77 | '/api/trans/vip/language', 78 | { 79 | 'q': q, 80 | 'appid': _optionAppId, 81 | 'salt': salt.toString(), 82 | 'sign': sign.toString(), 83 | }, 84 | ); 85 | 86 | final response = await http.post( 87 | uri, 88 | headers: { 89 | 'Content-Type': 'application/x-www-form-urlencoded', 90 | 'Accept': 'application/json', 91 | }, 92 | ); 93 | Map data = json.decode(utf8.decode(response.bodyBytes)); 94 | 95 | if (data['error_code'] != null && data['error_code'] != 0) { 96 | throw UniTranslateClientError( 97 | code: data['error_code'].toString(), 98 | message: data['error_msg'], 99 | ); 100 | } 101 | 102 | detections = [ 103 | TextDetection( 104 | detectedLanguage: data['data']['src'], 105 | text: q, 106 | ), 107 | ]; 108 | 109 | return DetectLanguageResponse( 110 | detections: detections, 111 | ); 112 | } 113 | 114 | @override 115 | Future lookUp(LookUpRequest request) async { 116 | throw UnimplementedError(); 117 | } 118 | 119 | @override 120 | Future translate(TranslateRequest request) async { 121 | List translations = []; 122 | 123 | String q = request.text; 124 | 125 | final salt = Random().nextInt(999999); 126 | final sign = _md5('$_optionAppId$q$salt$_optionAppKey'); 127 | 128 | Uri uri = Uri.https( 129 | 'fanyi-api.baidu.com', 130 | '/api/trans/vip/translate', 131 | { 132 | 'q': request.text, 133 | 'from': _convertLanguageCode(request.sourceLanguage) ?? 'auto', 134 | 'to': _convertLanguageCode(request.targetLanguage), 135 | 'appid': _optionAppId, 136 | 'salt': salt.toString(), 137 | 'sign': sign.toString(), 138 | 'dict': '0', 139 | }, 140 | ); 141 | 142 | final response = await http.post( 143 | uri, 144 | headers: { 145 | 'Content-Type': 'application/x-www-form-urlencoded', 146 | 'Accept': 'application/json', 147 | }, 148 | ); 149 | Map data = json.decode(utf8.decode(response.bodyBytes)); 150 | 151 | if (data['error_code'] != null && data['error_code'] != 0) { 152 | throw UniTranslateClientError( 153 | code: data['error_code'].toString(), 154 | message: data['error_msg'], 155 | ); 156 | } 157 | 158 | translations = (data['trans_result'] as List).map((e) { 159 | return TextTranslation( 160 | text: e['dst'], 161 | ); 162 | }).toList(); 163 | 164 | return TranslateResponse( 165 | translations: translations, 166 | ); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_baidu 2 | description: Baidu translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | crypto: ^3.0.3 11 | http: ^1.1.2 12 | uni_translate_client: ^0.1.3 13 | 14 | dev_dependencies: 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /packages/translation_engine_baidu/test/translation_engine_baidu_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_baidu/translation_engine_baidu.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_caiyun 2 | 3 | Caiyun translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_caiyun.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_caiyun 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/lib/translation_engine_caiyun.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_caiyun; 2 | 3 | import 'dart:convert'; 4 | 5 | import 'package:http/http.dart' as http; 6 | import 'package:uni_translate_client/uni_translate_client.dart'; 7 | 8 | const String kEngineTypeCaiyun = 'caiyun'; 9 | 10 | const String _kEngineOptionKeyToken = 'token'; 11 | const String _kEngineOptionKeyRequestId = 'requestId'; 12 | 13 | class CaiyunTranslationEngine extends TranslationEngine { 14 | CaiyunTranslationEngine({ 15 | required super.identifier, 16 | super.option, 17 | }); 18 | 19 | static List optionKeys = [ 20 | _kEngineOptionKeyToken, 21 | _kEngineOptionKeyRequestId, 22 | ]; 23 | 24 | @override 25 | String get type => kEngineTypeCaiyun; 26 | 27 | @override 28 | List get supportedScopes { 29 | return [ 30 | TranslationEngineScope.translate, 31 | ]; 32 | } 33 | 34 | String get _optionToken => option?[_kEngineOptionKeyToken] ?? ''; 35 | String get _optionRequestId => option?[_kEngineOptionKeyRequestId] ?? ''; 36 | 37 | @override 38 | Future> getSupportedLanguagePairs() { 39 | return Future.value([ 40 | const LanguagePair(sourceLanguage: 'en', targetLanguage: 'zh'), 41 | const LanguagePair(sourceLanguage: 'ja', targetLanguage: 'zh'), 42 | const LanguagePair(sourceLanguage: 'zh', targetLanguage: 'en'), 43 | const LanguagePair(sourceLanguage: 'zh', targetLanguage: 'ja'), 44 | ]); 45 | } 46 | 47 | @override 48 | Future detectLanguage(DetectLanguageRequest request) { 49 | throw UnimplementedError(); 50 | } 51 | 52 | @override 53 | Future lookUp(LookUpRequest request) { 54 | throw UnimplementedError(); 55 | } 56 | 57 | @override 58 | Future translate(TranslateRequest request) async { 59 | List translations = []; 60 | 61 | String transType = 'auto'; 62 | if (request.sourceLanguage != null && request.targetLanguage != null) { 63 | transType = '${request.sourceLanguage}2${request.targetLanguage}'; 64 | } 65 | 66 | final payload = { 67 | 'source': [request.text], 68 | 'trans_type': transType, 69 | 'request_id': _optionRequestId, 70 | }; 71 | final response = await http.post( 72 | Uri.parse('http://api.interpreter.caiyunai.com/v1/translator'), 73 | headers: { 74 | 'Content-Type': 'application/json', 75 | 'X-Authorization': 'token $_optionToken', 76 | }, 77 | body: json.encode(payload), 78 | ); 79 | Map data = json.decode(utf8.decode(response.bodyBytes)); 80 | 81 | if (data['message'] != null) { 82 | throw UniTranslateClientError(message: data['message']); 83 | } 84 | 85 | translations = (data['target'] as List).map( 86 | (e) { 87 | return TextTranslation(text: e); 88 | }, 89 | ).toList(); 90 | 91 | return TranslateResponse( 92 | translations: translations, 93 | ); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_caiyun 2 | description: Caiyun translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | crypto: ^3.0.3 11 | http: ^1.1.2 12 | uni_translate_client: ^0.1.3 13 | 14 | dev_dependencies: 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /packages/translation_engine_caiyun/test/translation_engine_caiyun_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_caiyun/translation_engine_caiyun.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_deepl 2 | 3 | DeepL translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_deepl.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_deepl 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/lib/translation_engine_deepl.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_deepl; 2 | 3 | import 'dart:convert'; 4 | import 'dart:io'; 5 | 6 | import 'package:http/http.dart' as http; 7 | import 'package:uni_translate_client/uni_translate_client.dart'; 8 | 9 | const String kEngineTypeDeepL = 'deepl'; 10 | 11 | const String _kEngineOptionKeyAuthKey = 'authKey'; 12 | 13 | const Map _knownErrors = { 14 | '400': 'Bad request. Please check error message and your parameters.', 15 | '401': 16 | 'Authorization failed. Please supply a valid DeepL-Auth-Key via the Authorization header.', 17 | '403': 18 | 'Forbidden. The access to the requested resource is denied, because of insufficient access rights.', 19 | '404': 'The requested resource could not be found.', 20 | '413': 'The request size exceeds the limit.', 21 | '415': 22 | 'The requested entries format specified in the Accept header is not supported.', 23 | '429': 'Too many requests. Please wait and resend your request.', 24 | '456': 'Quota exceeded. The maximum amount of glossaries has been reached.', 25 | '503': 'Resource currently unavailable. Try again later.', 26 | '529': 'Too many requests. Please wait and resend your request.', 27 | '5**': 'Internal error', 28 | }; 29 | 30 | class DeepLTranslationEngine extends TranslationEngine { 31 | DeepLTranslationEngine({ 32 | required super.identifier, 33 | super.option, 34 | }); 35 | 36 | static List optionKeys = [ 37 | _kEngineOptionKeyAuthKey, 38 | ]; 39 | 40 | @override 41 | String get type => kEngineTypeDeepL; 42 | 43 | @override 44 | List get supportedScopes { 45 | return [ 46 | TranslationEngineScope.translate, 47 | ]; 48 | } 49 | 50 | bool get _isDeepLFree => _optionAuthKey.endsWith(':fx'); 51 | String get _optionAuthKey => option?[_kEngineOptionKeyAuthKey] ?? ''; 52 | 53 | @override 54 | Future detectLanguage(DetectLanguageRequest request) { 55 | throw UnimplementedError(); 56 | } 57 | 58 | @override 59 | Future lookUp(LookUpRequest request) { 60 | throw UnimplementedError(); 61 | } 62 | 63 | @override 64 | Future translate(TranslateRequest request) async { 65 | List translations = []; 66 | 67 | Map queryParameters = { 68 | 'auth_key': _optionAuthKey, 69 | 'text': request.text, 70 | 'source_lang': request.sourceLanguage!.toUpperCase(), 71 | 'target_lang': request.targetLanguage!.toUpperCase(), 72 | }; 73 | 74 | String host = _isDeepLFree ? 'api-free.deepl.com' : 'api.deepl.com'; 75 | var uri = Uri.https(host, '/v2/translate', queryParameters); 76 | 77 | final response = await http.post( 78 | uri, 79 | headers: { 80 | HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8', 81 | }, 82 | ); 83 | 84 | String? errorMessage; 85 | 86 | if (response.statusCode == 200) { 87 | Map data = json.decode(utf8.decode(response.bodyBytes)); 88 | 89 | if (data['translations'] != null) { 90 | Iterable l = data['translations'] as List; 91 | translations = l 92 | .map( 93 | (e) => TextTranslation( 94 | detectedSourceLanguage: e['detected_source_language'], 95 | text: e['text'], 96 | ), 97 | ) 98 | .toList(); 99 | } 100 | 101 | if (data['message'] != null) { 102 | errorMessage = [ 103 | data['message'], 104 | data['detail'] ?? '', 105 | ].join('\n'); 106 | } 107 | } else { 108 | errorMessage = _knownErrors['5**']; 109 | if (_knownErrors.containsKey('${response.statusCode}')) { 110 | errorMessage = _knownErrors['${response.statusCode}']; 111 | } 112 | } 113 | 114 | if ((errorMessage ?? '').trim().isNotEmpty) { 115 | throw UniTranslateClientError( 116 | message: errorMessage!, 117 | ); 118 | } 119 | 120 | return TranslateResponse( 121 | translations: translations, 122 | ); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_deepl 2 | description: DeepL translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | http: ^1.1.2 11 | uni_translate_client: ^0.1.3 12 | 13 | dev_dependencies: 14 | mostly_reasonable_lints: ^0.1.2 15 | test: ^1.0.0 16 | -------------------------------------------------------------------------------- /packages/translation_engine_deepl/test/translation_engine_deepl_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_deepl/translation_engine_deepl.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_google/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_google/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_google/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_google/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_google 2 | 3 | Google translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_google.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_google 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_google/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_google/lib/translation_engine_google.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_google; 2 | 3 | import 'dart:convert'; 4 | import 'dart:io'; 5 | 6 | import 'package:http/http.dart' as http; 7 | import 'package:uni_translate_client/uni_translate_client.dart'; 8 | 9 | const String kEngineTypeGoogle = 'google'; 10 | 11 | const String _kEngineOptionKeyApiKey = 'apiKey'; 12 | 13 | class GoogleTranslationEngine extends TranslationEngine { 14 | GoogleTranslationEngine({ 15 | required super.identifier, 16 | super.option, 17 | }); 18 | 19 | static List optionKeys = [ 20 | _kEngineOptionKeyApiKey, 21 | ]; 22 | 23 | @override 24 | String get type => kEngineTypeGoogle; 25 | 26 | @override 27 | List get supportedScopes { 28 | return [ 29 | TranslationEngineScope.detectLanguage, 30 | TranslationEngineScope.translate, 31 | ]; 32 | } 33 | 34 | String get _optionApiKey => option?[_kEngineOptionKeyApiKey] ?? ''; 35 | 36 | @override 37 | Future detectLanguage( 38 | DetectLanguageRequest request, 39 | ) async { 40 | List detections = []; 41 | 42 | var response = await http.post( 43 | Uri.https( 44 | 'translation.googleapis.com', 45 | '/language/translate/v2/detect', 46 | {'key': _optionApiKey}, 47 | ), 48 | body: json.encode({ 49 | 'q': request.texts.first, 50 | }), 51 | headers: { 52 | HttpHeaders.contentTypeHeader: ContentType.json.toString(), 53 | }, 54 | ); 55 | Map data = json.decode(utf8.decode(response.bodyBytes)); 56 | 57 | if (response.statusCode != 200) { 58 | throw UniTranslateClientError( 59 | code: data['error']['code'].toString(), 60 | message: data['error']['message'], 61 | ); 62 | } 63 | 64 | try { 65 | detections = List.from(data['data']['detections'][0]) 66 | .map( 67 | (e) => TextDetection( 68 | detectedLanguage: e['language'], 69 | text: request.texts.first, 70 | ), 71 | ) 72 | .toList(); 73 | } catch (error) { 74 | throw UniTranslateClientError(message: 'Failed to parse detections'); 75 | } 76 | 77 | return DetectLanguageResponse( 78 | detections: detections, 79 | ); 80 | } 81 | 82 | @override 83 | Future lookUp(LookUpRequest request) async { 84 | throw UnimplementedError(); 85 | } 86 | 87 | @override 88 | Future translate(TranslateRequest request) async { 89 | List translations = []; 90 | 91 | var response = await http.post( 92 | Uri.https( 93 | 'translation.googleapis.com', 94 | '/language/translate/v2', 95 | {'key': _optionApiKey}, 96 | ), 97 | body: json.encode({ 98 | 'q': request.text, 99 | 'source': request.sourceLanguage, 100 | 'target': request.targetLanguage, 101 | 'format': 'text', 102 | }), 103 | headers: { 104 | // HttpHeaders.authorizationHeader: 'Bearer $_optionApiKey', 105 | HttpHeaders.contentTypeHeader: ContentType.json.toString(), 106 | }, 107 | ); 108 | Map data = json.decode(utf8.decode(response.bodyBytes)); 109 | 110 | if (response.statusCode != 200) { 111 | throw UniTranslateClientError( 112 | code: data['error']['code'].toString(), 113 | message: data['error']['message'], 114 | ); 115 | } 116 | 117 | translations = List.from(data['data']['translations']) 118 | .map((e) => TextTranslation(text: e['translatedText'])) 119 | .toList(); 120 | 121 | return TranslateResponse( 122 | translations: translations, 123 | ); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /packages/translation_engine_google/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_google 2 | description: Google translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | crypto: ^3.0.3 11 | http: ^1.1.2 12 | uni_translate_client: ^0.1.3 13 | 14 | dev_dependencies: 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /packages/translation_engine_google/test/translation_engine_google_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_google/translation_engine_google.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_ibmwatson 2 | 3 | IBMWatson translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_ibmwatson.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_ibmwatson 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/lib/translation_engine_ibmwatson.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_ibmwatson; 2 | 3 | import 'dart:convert'; 4 | 5 | import 'package:http/http.dart' as http; 6 | import 'package:uni_translate_client/uni_translate_client.dart'; 7 | 8 | const String kEngineTypeIBMWatson = 'ibmwatson'; 9 | 10 | const String _kEngineOptionKeyApiKey = 'apiKey'; 11 | const String _kEngineOptionKeyApiUrl = 'apiUrl'; 12 | 13 | String _base64(String data) { 14 | return base64.encode(utf8.encode(data)).toString(); 15 | } 16 | 17 | class IBMWatsonTranslationEngine extends TranslationEngine { 18 | IBMWatsonTranslationEngine({ 19 | required super.identifier, 20 | super.option, 21 | }); 22 | 23 | static List optionKeys = [ 24 | _kEngineOptionKeyApiKey, 25 | _kEngineOptionKeyApiUrl, 26 | ]; 27 | 28 | @override 29 | String get type => kEngineTypeIBMWatson; 30 | 31 | @override 32 | List get supportedScopes { 33 | return [ 34 | TranslationEngineScope.translate, 35 | ]; 36 | } 37 | 38 | String get _optionApiKey => option?[_kEngineOptionKeyApiKey] ?? ''; 39 | String get _optionApiUrl => option?[_kEngineOptionKeyApiUrl] ?? ''; 40 | 41 | @override 42 | Future detectLanguage(DetectLanguageRequest request) { 43 | throw UnimplementedError(); 44 | } 45 | 46 | @override 47 | Future lookUp(LookUpRequest request) async { 48 | throw UnimplementedError(); 49 | } 50 | 51 | @override 52 | Future translate(TranslateRequest request) async { 53 | List translations = []; 54 | 55 | String modelId = '${request.sourceLanguage}-${request.targetLanguage}'; 56 | 57 | Uri uri = Uri.parse('$_optionApiUrl/v3/translate?version=2018-05-01'); 58 | 59 | var response = await http.post( 60 | uri, 61 | headers: { 62 | 'Authorization': 'Basic ${_base64('apikey:$_optionApiKey')}', 63 | 'Content-Type': 'application/json', 64 | }, 65 | body: json.encode({ 66 | 'model_id': modelId, 67 | 'text': [request.text], 68 | }), 69 | ); 70 | 71 | Map data = json.decode(utf8.decode(response.bodyBytes)); 72 | 73 | translations = (data['translations'] as List).map((e) { 74 | return TextTranslation(text: e['translation']); 75 | }).toList(); 76 | 77 | return TranslateResponse( 78 | translations: translations, 79 | ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_ibmwatson 2 | description: IBMWatson translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | http: ^1.1.2 11 | uni_translate_client: ^0.1.3 12 | 13 | dev_dependencies: 14 | mostly_reasonable_lints: ^0.1.2 15 | test: ^1.0.0 16 | -------------------------------------------------------------------------------- /packages/translation_engine_ibmwatson/test/translation_engine_ibmwatson_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_ibmwatson/translation_engine_ibmwatson.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_iciba 2 | 3 | Iciba translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_iciba.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_iciba 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/lib/translation_engine_iciba.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_iciba; 2 | 3 | import 'dart:convert'; 4 | import 'dart:io'; 5 | 6 | import 'package:http/http.dart' as http; 7 | import 'package:uni_translate_client/uni_translate_client.dart'; 8 | 9 | const String kEngineTypeIciba = 'iciba'; 10 | 11 | const String _kEngineOptionKeyApiKey = 'apiKey'; 12 | 13 | class IcibaTranslationEngine extends TranslationEngine { 14 | IcibaTranslationEngine({ 15 | required super.identifier, 16 | super.option, 17 | }); 18 | 19 | static List optionKeys = [ 20 | _kEngineOptionKeyApiKey, 21 | ]; 22 | 23 | @override 24 | String get type => kEngineTypeIciba; 25 | 26 | @override 27 | List get supportedScopes { 28 | return [ 29 | TranslationEngineScope.lookUp, 30 | ]; 31 | } 32 | 33 | String get _optionApiKey => option?[_kEngineOptionKeyApiKey] ?? ''; 34 | 35 | @override 36 | Future detectLanguage(DetectLanguageRequest request) { 37 | throw UnimplementedError(); 38 | } 39 | 40 | @override 41 | Future lookUp(LookUpRequest request) async { 42 | List translations = []; 43 | String? word; 44 | String? tip; 45 | List? tags; 46 | List? definitions; 47 | List? pronunciations; 48 | List? images; 49 | List? phrases; 50 | List? tenses; 51 | List? sentences; 52 | 53 | if (!(request.sourceLanguage == 'en' && request.targetLanguage == 'zh')) { 54 | throw UniTranslateClientError(message: 'Not Supported'); 55 | } 56 | 57 | Uri uri = Uri.http( 58 | 'dict-co.iciba.com', 59 | '/api/dictionary.php', 60 | { 61 | 'w': request.word.toLowerCase(), 62 | 'key': _optionApiKey, 63 | 'type': 'json', 64 | }, 65 | ); 66 | 67 | var response = await http.get(uri); 68 | if (response.headers[HttpHeaders.contentTypeHeader]?.contains('text/xml') == 69 | true) { 70 | throw UniTranslateClientError(message: 'Please check your key'); 71 | } 72 | 73 | Map data = json.decode(utf8.decode(response.bodyBytes)); 74 | 75 | word = data['word_name']; 76 | 77 | var symbol = data['symbols'][0]; 78 | var parts = symbol['parts']; 79 | 80 | if (parts != null) { 81 | definitions = (parts as List).map((e) { 82 | String name = e['part']; 83 | List values = 84 | (e['means'] as List).map((e) => e.toString()).toList(); 85 | 86 | return WordDefinition( 87 | name: name, 88 | values: values, 89 | ); 90 | }).toList(); 91 | 92 | pronunciations = [ 93 | WordPronunciation( 94 | type: 'uk', 95 | phoneticSymbol: symbol['ph_en'], 96 | audioUrl: symbol['ph_en_mp3'], 97 | ), 98 | WordPronunciation( 99 | type: 'us', 100 | phoneticSymbol: symbol['ph_am'], 101 | audioUrl: symbol['ph_am_mp3'], 102 | ), 103 | ] 104 | .where( 105 | (e) => 106 | (e.phoneticSymbol ?? '').isNotEmpty || 107 | (e.audioUrl ?? '').isNotEmpty, 108 | ) 109 | .toList(); 110 | } 111 | 112 | if (data['exchange'] != null) { 113 | Map map = { 114 | 'word_pl': '复数', 115 | 'word_third': '第三人称单数', 116 | 'word_past': '过去式', 117 | 'word_done': '过去分词', 118 | 'word_ing': '现在分词', 119 | 'word_er': 'word_er', 120 | 'word_est': 'word_est', 121 | }; 122 | tenses = (data['exchange'] as Map) 123 | .keys 124 | .map((k) { 125 | String name = map[k] ?? ''; 126 | dynamic value = (data['exchange'][k]); 127 | List values = []; 128 | 129 | if (value is List) { 130 | values = (value).map((e) => e.toString()).toList(); 131 | } 132 | 133 | return WordTense( 134 | name: name, 135 | values: values, 136 | ); 137 | }) 138 | .where((e) => (e.values ?? []).isNotEmpty) 139 | .toList(); 140 | 141 | if (tenses.isEmpty) { 142 | tenses = null; 143 | } 144 | } 145 | 146 | if ((pronunciations ?? []).isEmpty && (definitions ?? []).isEmpty) { 147 | throw UniTranslateClientError(message: 'Resource not found.'); 148 | } 149 | 150 | return LookUpResponse( 151 | translations: translations, 152 | word: word, 153 | tip: tip, 154 | tags: tags, 155 | definitions: definitions, 156 | pronunciations: pronunciations, 157 | images: images, 158 | phrases: phrases, 159 | tenses: tenses, 160 | sentences: sentences, 161 | ); 162 | } 163 | 164 | @override 165 | Future translate(TranslateRequest request) async { 166 | throw UnimplementedError(); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_iciba 2 | description: Iciba translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | http: ^1.1.2 11 | uni_translate_client: ^0.1.3 12 | 13 | dev_dependencies: 14 | mostly_reasonable_lints: ^0.1.2 15 | test: ^1.0.0 16 | -------------------------------------------------------------------------------- /packages/translation_engine_iciba/test/translate_engine_iciba_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_iciba/translation_engine_iciba.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | .packages 30 | build/ 31 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 8 | channel: stable 9 | 10 | project_type: plugin 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 17 | base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2 18 | 19 | # User provided section 20 | 21 | # List of Local paths (relative to this file) that should be 22 | # ignored by the migrate tool. 23 | # 24 | # Files that are not part of the templates will be ignored by default. 25 | unmanaged_files: 26 | - 'lib/main.dart' 27 | - 'ios/Runner.xcodeproj/project.pbxproj' 28 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `dart_openai` to 5.0.0 8 | 9 | ## 0.1.4 10 | 11 | * handling error cases 12 | 13 | ## 0.1.3 14 | 15 | * first release 16 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_openai 2 | 3 | OpenAI translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_openai.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_openai 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/lib/translation_engine_openai.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_openai; 2 | 3 | import 'dart:async'; 4 | 5 | import 'package:dart_openai/dart_openai.dart'; 6 | import 'package:uni_translate_client/uni_translate_client.dart'; 7 | 8 | const String kEngineTypeOpenAI = 'openai'; 9 | 10 | const String _kEngineOptionKeyBaseUrl = 'baseUrl'; 11 | const String _kEngineOptionKeyApiKey = 'apiKey'; 12 | const String _kEngineOptionKeyPrompt = 'prompt'; 13 | 14 | const String _kDefaultPrompt = 15 | 'You are a translation engine that can only translate text and cannot interpret it. ' 16 | 'translate from \${sourceLanguage} to \${targetLanguage}'; 17 | 18 | class OpenAITranslationEngine extends TranslationEngine { 19 | OpenAITranslationEngine({ 20 | required super.identifier, 21 | super.option, 22 | }); 23 | 24 | static List optionKeys = [ 25 | _kEngineOptionKeyBaseUrl, 26 | _kEngineOptionKeyApiKey, 27 | _kEngineOptionKeyPrompt, 28 | ]; 29 | 30 | @override 31 | String get type => kEngineTypeOpenAI; 32 | 33 | @override 34 | List get supportedScopes { 35 | return [ 36 | TranslationEngineScope.translate, 37 | ]; 38 | } 39 | 40 | String get _optionBaseUrl => option?[_kEngineOptionKeyBaseUrl] ?? ''; 41 | String get _optionApiKey => option?[_kEngineOptionKeyApiKey] ?? ''; 42 | String get _optionPrompt => 43 | option?[_kEngineOptionKeyPrompt] ?? _kDefaultPrompt; 44 | 45 | @override 46 | Future detectLanguage(DetectLanguageRequest request) { 47 | throw UnimplementedError(); 48 | } 49 | 50 | @override 51 | Future lookUp(LookUpRequest request) async { 52 | throw UnimplementedError(); 53 | } 54 | 55 | @override 56 | Future translate(TranslateRequest request) async { 57 | Completer completer = Completer(); 58 | 59 | StreamTranslateResponse translateResponse = StreamTranslateResponse( 60 | translations: [], 61 | streamController: StreamController(sync: true), 62 | ); 63 | 64 | OpenAI.apiKey = _optionApiKey; 65 | if (_optionBaseUrl.isNotEmpty) { 66 | OpenAI.baseUrl = _optionBaseUrl; 67 | } 68 | 69 | final chatCompletionModel = OpenAI.instance.chat.createStream( 70 | model: 'gpt-3.5-turbo', 71 | messages: [ 72 | OpenAIChatCompletionChoiceMessageModel( 73 | role: OpenAIChatMessageRole.system, 74 | content: [ 75 | OpenAIChatCompletionChoiceMessageContentItemModel.text( 76 | _optionPrompt 77 | .replaceFirst('\${sourceLanguage}', request.sourceLanguage!) 78 | .replaceFirst('\${targetLanguage}', request.targetLanguage!), 79 | ), 80 | ], 81 | ), 82 | OpenAIChatCompletionChoiceMessageModel( 83 | role: OpenAIChatMessageRole.user, 84 | content: [ 85 | OpenAIChatCompletionChoiceMessageContentItemModel.text( 86 | request.text, 87 | ), 88 | ], 89 | ), 90 | ], 91 | ); 92 | 93 | String translatedText = ''; 94 | chatCompletionModel.listen( 95 | (streamChatCompletion) { 96 | final content = streamChatCompletion.choices.first.delta.content; 97 | if (content == null || content.isEmpty) return; 98 | translatedText += content.first?.text ?? ''; 99 | 100 | final textTranslation = TextTranslation(text: translatedText); 101 | if (translateResponse.translations.isEmpty) { 102 | translateResponse.translations = [textTranslation]; 103 | completer.complete(translateResponse); 104 | } else { 105 | translateResponse.translations = [textTranslation]; 106 | } 107 | translateResponse.sink.add(translateResponse); 108 | }, 109 | onDone: () { 110 | translateResponse.sink.close(); 111 | }, 112 | onError: (Object error, StackTrace stackTrace) { 113 | translateResponse.sink.addError(error, stackTrace); 114 | if (!completer.isCompleted) { 115 | completer.completeError(error, stackTrace); 116 | } 117 | translateResponse.sink.close(); 118 | }, 119 | cancelOnError: true, 120 | ); 121 | return completer.future; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /packages/translation_engine_openai/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_openai 2 | description: OpenAI translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | dart_openai: ^5.1.0 11 | uni_translate_client: ^0.1.3 12 | 13 | dev_dependencies: 14 | mostly_reasonable_lints: ^0.1.2 -------------------------------------------------------------------------------- /packages/translation_engine_tencent/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_tencent 2 | 3 | Tencent translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_tencent.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_tencent 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | 14 | ## Related Links 15 | 16 | - https://cloud.tencent.com/document/product/551/15619 17 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/lib/translation_engine_tencent.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_tencent; 2 | 3 | import 'dart:convert'; 4 | import 'dart:math'; 5 | 6 | import 'package:crypto/crypto.dart'; 7 | import 'package:http/http.dart' as http; 8 | import 'package:uni_translate_client/uni_translate_client.dart'; 9 | 10 | const String kEngineTypeTencent = 'tencent'; 11 | 12 | const String _kEngineOptionKeySecretId = 'secretId'; 13 | const String _kEngineOptionKeySecretKey = 'secretKey'; 14 | 15 | String _signature(String key, String data) { 16 | var hmacSha1 = Hmac(sha1, utf8.encode(key)); 17 | var digest = hmacSha1.convert(utf8.encode(data)); 18 | 19 | return base64.encode(digest.bytes).toString(); 20 | } 21 | 22 | class TencentTranslationEngine extends TranslationEngine { 23 | TencentTranslationEngine({ 24 | required super.identifier, 25 | super.option, 26 | }); 27 | 28 | static List optionKeys = [ 29 | _kEngineOptionKeySecretId, 30 | _kEngineOptionKeySecretKey, 31 | ]; 32 | 33 | @override 34 | String get type => kEngineTypeTencent; 35 | 36 | @override 37 | List get supportedScopes { 38 | return [ 39 | TranslationEngineScope.translate, 40 | ]; 41 | } 42 | 43 | String get _optionSecretId => option?[_kEngineOptionKeySecretId] ?? ''; 44 | String get _optionSecretKey => option?[_kEngineOptionKeySecretKey] ?? ''; 45 | 46 | @override 47 | Future detectLanguage( 48 | DetectLanguageRequest request, 49 | ) async { 50 | List detections = []; 51 | 52 | Map body = { 53 | 'Action': 'LanguageDetect', 54 | 'Language': 'zh-CN', 55 | 'Nonce': '${Random().nextInt(9999)}', 56 | 'ProjectId': '0', 57 | 'Region': 'ap-guangzhou', 58 | 'SecretId': _optionSecretId, 59 | 'Text': request.texts.first, 60 | 'Timestamp': '${DateTime.now().millisecondsSinceEpoch ~/ 1000}', 61 | 'Version': '2018-03-21', 62 | }; 63 | 64 | List keys = body.keys.toList(); 65 | keys.sort((a, b) => a.compareTo(b)); 66 | String query = keys.map((key) => '$key=${body[key]}').join('&'); 67 | 68 | String endpoint = 'tmt.tencentcloudapi.com'; 69 | String srcStr = 'POST$endpoint/?$query'; 70 | String signature = _signature(_optionSecretKey, srcStr); 71 | 72 | body.putIfAbsent('Signature', () => signature); 73 | 74 | keys = body.keys.toList(); 75 | keys.sort((a, b) => a.compareTo(b)); 76 | query = keys.map((key) => '$key=${body[key]}').join('&'); 77 | 78 | var response = await http.post( 79 | Uri.parse('https://$endpoint'), 80 | headers: { 81 | 'Content-Type': 'application/x-www-form-urlencoded', 82 | 'Accept': 'application/json', 83 | }, 84 | body: body, 85 | ); 86 | 87 | Map data = json.decode(utf8.decode(response.bodyBytes)); 88 | 89 | detections = [ 90 | TextDetection( 91 | detectedLanguage: data['Response']['Lang'], 92 | text: request.texts.first, 93 | ), 94 | ]; 95 | 96 | return DetectLanguageResponse( 97 | detections: detections, 98 | ); 99 | } 100 | 101 | @override 102 | Future lookUp(LookUpRequest request) async { 103 | throw UnimplementedError(); 104 | } 105 | 106 | @override 107 | Future translate(TranslateRequest request) async { 108 | List translations = []; 109 | 110 | Map body = { 111 | 'Action': 'TextTranslate', 112 | 'Language': 'zh-CN', 113 | 'Nonce': '${Random().nextInt(9999)}', 114 | 'ProjectId': '0', 115 | 'Region': 'ap-guangzhou', 116 | 'SecretId': _optionSecretId, 117 | 'Source': request.sourceLanguage ?? 'auto', 118 | 'SourceText': request.text, 119 | 'Target': request.targetLanguage!, 120 | 'Timestamp': '${DateTime.now().millisecondsSinceEpoch ~/ 1000}', 121 | 'Version': '2018-03-21', 122 | }; 123 | 124 | List keys = body.keys.toList(); 125 | keys.sort((a, b) => a.compareTo(b)); 126 | String query = keys.map((key) => '$key=${body[key]}').join('&'); 127 | 128 | String endpoint = 'tmt.tencentcloudapi.com'; 129 | String srcStr = 'POST$endpoint/?$query'; 130 | String signature = _signature(_optionSecretKey, srcStr); 131 | 132 | body.putIfAbsent('Signature', () => signature); 133 | 134 | keys = body.keys.toList(); 135 | keys.sort((a, b) => a.compareTo(b)); 136 | query = keys.map((key) => '$key=${body[key]}').join('&'); 137 | 138 | var response = await http.post( 139 | Uri.parse('https://$endpoint'), 140 | headers: { 141 | 'Content-Type': 'application/x-www-form-urlencoded', 142 | 'Accept': 'application/json', 143 | }, 144 | body: body, 145 | ); 146 | 147 | Map data = json.decode(utf8.decode(response.bodyBytes)); 148 | 149 | if (data['Response']['Error'] != null) { 150 | throw UniTranslateClientError( 151 | code: data['Response']['Error']['Code'], 152 | message: data['Response']['Error']['Message'], 153 | ); 154 | } 155 | translations = [ 156 | TextTranslation(text: data['Response']['TargetText']), 157 | ]; 158 | 159 | return TranslateResponse( 160 | translations: translations, 161 | ); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_tencent 2 | description: Tencent translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | crypto: ^3.0.3 11 | http: ^1.1.2 12 | uni_translate_client: ^0.1.3 13 | 14 | dev_dependencies: 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /packages/translation_engine_tencent/test/translation_engine_tencent_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_tencent/translation_engine_tencent.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.5 6 | 7 | * chore: Bump `http` to 1.1.2 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/README.md: -------------------------------------------------------------------------------- 1 | # translation_engine_youdao 2 | 3 | Youdao translation engine 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/translation_engine_youdao.svg 8 | [pub-url]: https://pub.dev/packages/translation_engine_youdao 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/lib/translation_engine_youdao.dart: -------------------------------------------------------------------------------- 1 | library translation_engine_youdao; 2 | 3 | import 'dart:convert'; 4 | 5 | import 'package:crypto/crypto.dart'; 6 | import 'package:http/http.dart' as http; 7 | import 'package:translation_engine_youdao/youdao_api_known_errors.dart'; 8 | import 'package:uni_translate_client/uni_translate_client.dart'; 9 | 10 | const String kEngineTypeYoudao = 'youdao'; 11 | 12 | const String _kEngineOptionKeyAppKey = 'appKey'; 13 | const String _kEngineOptionKeyAppSecret = 'appSecret'; 14 | 15 | String _md5(String data) { 16 | return md5.convert(utf8.encode(data)).toString(); 17 | } 18 | 19 | String _sha256(String data) { 20 | return sha256.convert(utf8.encode(data)).toString(); 21 | } 22 | 23 | class YoudaoTranslationEngine extends TranslationEngine { 24 | YoudaoTranslationEngine({ 25 | required super.identifier, 26 | super.option, 27 | }); 28 | 29 | static List optionKeys = [ 30 | _kEngineOptionKeyAppKey, 31 | _kEngineOptionKeyAppSecret, 32 | ]; 33 | 34 | @override 35 | String get type => kEngineTypeYoudao; 36 | 37 | @override 38 | List get supportedScopes { 39 | return [ 40 | TranslationEngineScope.lookUp, 41 | ]; 42 | } 43 | 44 | String get _optionAppKey => option?[_kEngineOptionKeyAppKey] ?? ''; 45 | String get _optionAppSecret => option?[_kEngineOptionKeyAppSecret] ?? ''; 46 | 47 | @override 48 | Future detectLanguage(DetectLanguageRequest request) { 49 | throw UnimplementedError(); 50 | } 51 | 52 | @override 53 | Future lookUp(LookUpRequest request) async { 54 | List translations = []; 55 | String? word; 56 | String? tip; 57 | List? tags; 58 | List? definitions; 59 | List? pronunciations; 60 | List? images; 61 | List? phrases; 62 | List? tenses; 63 | List? sentences; 64 | 65 | String q = request.word; 66 | String input = q; 67 | if (q.length > 20) { 68 | input = '${q.substring(0, 10)}${q.length}${q.substring(q.length - 10)}'; 69 | } 70 | 71 | final curtime = (DateTime.now().millisecondsSinceEpoch ~/ 1000); 72 | final salt = _md5('translation_engine_youdao'); 73 | final sign = _sha256('$_optionAppKey$input$salt$curtime$_optionAppSecret'); 74 | 75 | Uri uri = Uri.https( 76 | 'openapi.youdao.com', 77 | '/api', 78 | { 79 | 'q': request.word, 80 | 'from': request.sourceLanguage ?? 'auto', 81 | 'to': request.targetLanguage, 82 | 'appKey': _optionAppKey, 83 | 'salt': salt.toString(), 84 | 'sign': sign.toString(), 85 | 'signType': 'v3', 86 | 'curtime': '$curtime', 87 | }, 88 | ); 89 | 90 | var response = await http.get(uri); 91 | Map data = json.decode(utf8.decode(response.bodyBytes)); 92 | 93 | if (data['errorCode'] != '0') { 94 | String errorCode = data['errorCode']; 95 | String errorMessage = 'ErrorCode: $errorCode'; 96 | if (youdaoApiKnownErrors.containsKey(errorCode)) { 97 | errorMessage = youdaoApiKnownErrors[errorCode]!; 98 | } 99 | throw UniTranslateClientError(message: errorMessage); 100 | } 101 | 102 | // var query = data['query']; 103 | var translation = data['translation']; 104 | var basic = data['basic']; 105 | var returnPhrase = data['returnPhrase']; 106 | var tSpeakUrl = data['tSpeakUrl']; 107 | 108 | if (translation != null) { 109 | translations = 110 | (translation as List).map((v) => TextTranslation(text: v)).toList(); 111 | if (translations.length == 1) { 112 | translations[0] = translations[0].copyWith(audioUrl: tSpeakUrl); 113 | } 114 | } 115 | 116 | if (returnPhrase != null) { 117 | word = returnPhrase[0]; 118 | } 119 | 120 | if (basic != null) { 121 | var examType = basic['exam_type']; 122 | var explains = basic['explains']; 123 | var wfs = basic['wfs']; 124 | 125 | if (examType != null) { 126 | tags = (examType as List).map((e) { 127 | return WordTag(name: e); 128 | }).toList(); 129 | } 130 | if (explains != null) { 131 | definitions = (explains as List).map((e) { 132 | String def = e.toString(); 133 | int dotIndex = def.indexOf('. '); 134 | String? name = dotIndex >= 0 ? def.substring(0, dotIndex + 1) : null; 135 | String value = dotIndex >= 0 ? def.substring(dotIndex + 2) : def; 136 | List values = value.split(';'); 137 | 138 | return WordDefinition( 139 | name: name, 140 | values: values, 141 | ); 142 | }).toList(); 143 | } 144 | 145 | pronunciations = [ 146 | WordPronunciation( 147 | type: 'uk', 148 | phoneticSymbol: basic['uk-phonetic'], 149 | audioUrl: basic['uk-speech'], 150 | ), 151 | WordPronunciation( 152 | type: 'us', 153 | phoneticSymbol: basic['us-phonetic'], 154 | audioUrl: basic['us-speech'], 155 | ), 156 | ] 157 | .where( 158 | (e) => 159 | (e.phoneticSymbol ?? '').isNotEmpty || 160 | (e.audioUrl ?? '').isNotEmpty, 161 | ) 162 | .toList(); 163 | 164 | if (wfs != null) { 165 | tenses = (wfs as List).map((e) { 166 | var wf = e['wf']; 167 | String name = wf['name']; 168 | String value = wf['value']; 169 | 170 | List values = [value]; 171 | if (value.contains('或')) { 172 | values = value.split('或'); 173 | } 174 | 175 | return WordTense( 176 | name: name, 177 | values: values, 178 | ); 179 | }).toList(); 180 | } 181 | } 182 | 183 | if ((definitions ?? []).isNotEmpty || (pronunciations ?? []).isNotEmpty) { 184 | Uri uri2 = Uri.https( 185 | 'picdict.youdao.com', 186 | '/search', 187 | { 188 | 'q': request.word, 189 | 'le': request.sourceLanguage, 190 | }, 191 | ); 192 | 193 | try { 194 | var response2 = await http.get(uri2); 195 | Map data2 = json.decode(response2.body); 196 | 197 | if (data2['data']['pic'] != null) { 198 | images = (data2['data']['pic'] as List) 199 | .map((e) => WordImage(url: e['url'])) 200 | .toList(); 201 | } 202 | } catch (error) { 203 | // skip 204 | } 205 | } 206 | 207 | return LookUpResponse( 208 | translations: translations, 209 | word: word, 210 | tip: tip, 211 | tags: tags, 212 | definitions: definitions, 213 | pronunciations: pronunciations, 214 | images: images, 215 | phrases: phrases, 216 | tenses: tenses, 217 | sentences: sentences, 218 | ); 219 | } 220 | 221 | @override 222 | Future translate(TranslateRequest request) { 223 | throw UnimplementedError(); 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/lib/youdao_api_known_errors.dart: -------------------------------------------------------------------------------- 1 | const Map youdaoApiKnownErrors = { 2 | '101': '缺少必填的参数,首先确保必填参数齐全,然后确认参数书写是否正确。', 3 | '102': '不支持的语言类型', 4 | '103': '翻译文本过长', 5 | '104': '不支持的API类型', 6 | '105': '不支持的签名类型', 7 | '106': '不支持的响应类型', 8 | '107': '不支持的传输加密类型', 9 | '108': '应用ID无效,注册账号,登录后台创建应用和实例并完成绑定,可获得应用ID和应用密钥等信息', 10 | '109': 'batchLog格式不正确', 11 | '110': 12 | '无相关服务的有效实例,应用没有绑定服务实例,可以新建服务实例,绑定服务实例。注:某些服务的翻译结果发音需要tts实例,需要在控制台创建语音合成实例绑定应用后方能使用。', 13 | '111': '开发者账号无效', 14 | '112': '请求服务无效', 15 | '113': 'q不能为空', 16 | '114': '不支持的图片传输方式', 17 | '116': 'strict字段取值无效,请参考文档填写正确参数值', 18 | '201': '解密失败,可能为DES,BASE64,URLDecode的错误', 19 | '202': '签名检验失败,如果确认应用ID和应用密钥的正确性,仍返回202,一般是编码问题。请确保翻译文本 q 为UTF-8编码.', 20 | '203': '访问IP地址不在可访问IP列表', 21 | '205': 22 | '请求的接口与应用的平台类型不一致,确保接入方式(Android SDK、IOS SDK、API)与创建的应用平台类型一致。如有疑问请参考入门指南', 23 | '206': '因为时间戳无效导致签名校验失败', 24 | '207': '重放请求', 25 | '301': '辞典查询失败', 26 | '302': '翻译查询失败', 27 | '303': '服务端的其它异常', 28 | '304': '会话闲置太久超时', 29 | '401': '账户已经欠费,请进行账户充值', 30 | '402': 'offlinesdk不可用', 31 | '411': '访问频率受限,请稍后访问', 32 | '412': '长请求过于频繁,请稍后访问', 33 | '1001': '无效的OCR类型', 34 | '1002': '不支持的OCR image类型', 35 | '1003': '不支持的OCR Language类型', 36 | '1004': '识别图片过大', 37 | '1201': '图片base64解密失败', 38 | '1301': 'OCR段落识别失败', 39 | '1411': '访问频率受限', 40 | '1412': '超过最大识别字节数', 41 | '2003': '不支持的语言识别Language类型', 42 | '2004': '合成字符过长', 43 | '2005': '不支持的音频文件类型', 44 | '2006': '不支持的发音类型', 45 | '2201': '解密失败', 46 | '2301': '服务的异常', 47 | '2411': '访问频率受限,请稍后访问', 48 | '2412': '超过最大请求字符数', 49 | '3001': '不支持的语音格式', 50 | '3002': '不支持的语音采样率', 51 | '3003': '不支持的语音声道', 52 | '3004': '不支持的语音上传类型', 53 | '3005': '不支持的语言类型', 54 | '3006': '不支持的识别类型', 55 | '3007': '识别音频文件过大', 56 | '3008': '识别音频时长过长', 57 | '3009': '不支持的音频文件类型', 58 | '3010': '不支持的发音类型', 59 | '3201': '解密失败', 60 | '3301': '语音识别失败', 61 | '3302': '语音翻译失败', 62 | '3303': '服务的异常', 63 | '3411': '访问频率受限,请稍后访问', 64 | '3412': '超过最大请求字符数', 65 | '4001': '不支持的语音识别格式', 66 | '4002': '不支持的语音识别采样率', 67 | '4003': '不支持的语音识别声道', 68 | '4004': '不支持的语音上传类型', 69 | '4005': '不支持的语言类型', 70 | '4006': '识别音频文件过大', 71 | '4007': '识别音频时长过长', 72 | '4201': '解密失败', 73 | '4301': '语音识别失败', 74 | '4303': '服务的异常', 75 | '4411': '访问频率受限,请稍后访问', 76 | '4412': '超过最大请求时长', 77 | '5001': '无效的OCR类型', 78 | '5002': '不支持的OCR image类型', 79 | '5003': '不支持的语言类型', 80 | '5004': '识别图片过大', 81 | '5005': '不支持的图片类型', 82 | '5006': '文件为空', 83 | '5201': '解密错误,图片base64解密失败', 84 | '5301': 'OCR段落识别失败', 85 | '5411': '访问频率受限', 86 | '5412': '超过最大识别流量', 87 | '9001': '不支持的语音格式', 88 | '9002': '不支持的语音采样率', 89 | '9003': '不支持的语音声道', 90 | '9004': '不支持的语音上传类型', 91 | '9005': '不支持的语音识别 Language类型', 92 | '9301': 'ASR识别失败', 93 | '9303': '服务器内部错误', 94 | '9411': '访问频率受限(超过最大调用次数)', 95 | '9412': '超过最大处理语音长度', 96 | '10001': '无效的OCR类型', 97 | '10002': '不支持的OCR image类型', 98 | '10004': '识别图片过大', 99 | '10201': '图片base64解密失败', 100 | '10301': 'OCR段落识别失败', 101 | '10411': '访问频率受限', 102 | '10412': '超过最大识别流量', 103 | '11001': '不支持的语音识别格式', 104 | '11002': '不支持的语音识别采样率', 105 | '11003': '不支持的语音识别声道', 106 | '11004': '不支持的语音上传类型', 107 | '11005': '不支持的语言类型', 108 | '11006': '识别音频文件过大', 109 | '11007': '识别音频时长过长,最大支持30s', 110 | '11201': '解密失败', 111 | '11301': '语音识别失败', 112 | '11303': '服务的异常', 113 | '11411': '访问频率受限,请稍后访问', 114 | '11412': '超过最大请求时长', 115 | '12001': '图片尺寸过大', 116 | '12002': '图片base64解密失败', 117 | '12003': '引擎服务器返回错误', 118 | '12004': '图片为空', 119 | '12005': '不支持的识别图片类型', 120 | '12006': '图片无匹配结果', 121 | '13001': '不支持的角度类型', 122 | '13002': '不支持的文件类型', 123 | '13003': '表格识别图片过大', 124 | '13004': '文件为空', 125 | '13301': '表格识别失败', 126 | '15001': '需要图片', 127 | '15002': '图片过大(1M)', 128 | '15003': '服务调用失败', 129 | '17001': '需要图片', 130 | '17002': '图片过大(1M)', 131 | '17003': '识别类型未找到', 132 | '17004': '不支持的识别类型', 133 | '17005': '服务调用失败', 134 | }; 135 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: translation_engine_youdao 2 | description: Youdao translation engine 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | crypto: ^3.0.3 11 | http: ^1.1.2 12 | uni_translate_client: ^0.1.3 13 | 14 | dev_dependencies: 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 17 | -------------------------------------------------------------------------------- /packages/translation_engine_youdao/test/translation_engine_youdao_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | // import 'package:translation_engine_youdao/translation_engine_youdao.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // expect(() => calculator.addOne(null), throwsNoSuchMethodError); 12 | }); 13 | } 14 | -------------------------------------------------------------------------------- /packages/uni_translate/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # dotenv environment variables file 15 | .env* 16 | 17 | # Avoid committing generated Javascript files: 18 | *.dart.js 19 | *.info.json # Produced by the --dump-info flag. 20 | *.js # When generated by dart2js. Don't specify *.js if your 21 | # project includes source files written in JavaScript. 22 | *.js_ 23 | *.js.deps 24 | *.js.map 25 | -------------------------------------------------------------------------------- /packages/uni_translate/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.6 2 | 3 | * some bug fixes 4 | 5 | ## 0.1.4 6 | 7 | * bump translation_engine_openai to 0.1.4 8 | 9 | ## 0.1.3 10 | 11 | * bump uni_translate_client to 0.1.3 12 | * add openai translation engine 13 | 14 | ## 0.1.2 15 | 16 | * chore: bump dart to 3.0.0 & fix lint issues 17 | 18 | ## 0.1.1 19 | 20 | * Support null-safety. 21 | 22 | ## 0.1.0 23 | 24 | * First release. 25 | -------------------------------------------------------------------------------- /packages/uni_translate/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/uni_translate/README.md: -------------------------------------------------------------------------------- 1 | # uni_translate 2 | 3 | A universal translate client. 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/uni_translate.svg 8 | [pub-url]: https://pub.dev/packages/uni_translate 9 | -------------------------------------------------------------------------------- /packages/uni_translate/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/uni_translate/lib/src/uni_translate.dart: -------------------------------------------------------------------------------- 1 | import 'package:uni_translate/uni_translate.dart'; 2 | 3 | class UniTranslate { 4 | UniTranslate._(); 5 | 6 | /// The shared instance of [UniTranslate]. 7 | static final UniTranslate instance = UniTranslate._(); 8 | 9 | final List _engines = []; 10 | 11 | /// Registers a [TranslationEngine]. 12 | void registerEngine(TranslationEngine engine) { 13 | _engines.add(engine); 14 | } 15 | 16 | /// Unregisters a [TranslationEngine]. 17 | void unregisterEngine(TranslationEngine engine) { 18 | _engines.remove(engine); 19 | } 20 | 21 | /// Returns a list of registered [TranslationEngine]s. 22 | List get engines => _engines; 23 | 24 | /// Returns a [TranslationEngine] by its [engineId]. 25 | TranslationEngine use(String engineId) { 26 | return _engines.firstWhere((engine) => engine.id == engineId); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/uni_translate/lib/uni_translate.dart: -------------------------------------------------------------------------------- 1 | library uni_translate; 2 | 3 | export 'package:translation_engine_baidu/translation_engine_baidu.dart'; 4 | export 'package:translation_engine_caiyun/translation_engine_caiyun.dart'; 5 | export 'package:translation_engine_deepl/translation_engine_deepl.dart'; 6 | export 'package:translation_engine_google/translation_engine_google.dart'; 7 | export 'package:translation_engine_iciba/translation_engine_iciba.dart'; 8 | export 'package:translation_engine_openai/translation_engine_openai.dart'; 9 | export 'package:translation_engine_tencent/translation_engine_tencent.dart'; 10 | export 'package:translation_engine_youdao/translation_engine_youdao.dart'; 11 | export 'package:uni_translate_client/uni_translate_client.dart'; 12 | 13 | export 'src/uni_translate.dart'; 14 | -------------------------------------------------------------------------------- /packages/uni_translate/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: uni_translate 2 | description: A universal translate client. 3 | version: 0.1.6 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | translation_engine_baidu: ^0.1.6 11 | translation_engine_caiyun: ^0.1.6 12 | translation_engine_deepl: ^0.1.6 13 | translation_engine_google: ^0.1.6 14 | translation_engine_iciba: ^0.1.6 15 | translation_engine_openai: ^0.1.4 16 | translation_engine_tencent: ^0.1.6 17 | translation_engine_youdao: ^0.1.6 18 | uni_translate_client: ^0.1.3 19 | 20 | dev_dependencies: 21 | mostly_reasonable_lints: ^0.1.2 22 | test: ^1.0.0 23 | -------------------------------------------------------------------------------- /packages/uni_translate/test/uni_translate_test.dart: -------------------------------------------------------------------------------- 1 | // import 'package:test/test.dart'; 2 | 3 | // import 'package:uni_translate/uni_translate.dart'; 4 | 5 | void main() { 6 | // test('adds one to input values', () { 7 | // final calculator = Calculator(); 8 | // expect(calculator.addOne(2), 3); 9 | // expect(calculator.addOne(-7), -6); 10 | // expect(calculator.addOne(0), 1); 11 | // }); 12 | } 13 | -------------------------------------------------------------------------------- /packages/uni_translate_client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # Avoid committing generated Javascript files: 15 | *.dart.js 16 | *.info.json # Produced by the --dump-info flag. 17 | *.js # When generated by dart2js. Don't specify *.js if your 18 | # project includes source files written in JavaScript. 19 | *.js_ 20 | *.js.deps 21 | *.js.map 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.7 2 | 3 | * some optimizations 4 | 5 | ## 0.1.6 6 | 7 | * some bug fixes 8 | 9 | ## 0.1.3 10 | 11 | * feat: Support for streaming output 12 | 13 | ## 0.1.2 14 | 15 | * chore: bump dart to 3.0.0 & fix lint issues 16 | 17 | ## 0.1.1 18 | 19 | * Support null-safety. 20 | 21 | ## 0.1.0 22 | 23 | * First release. 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2024 LiJianying 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/README.md: -------------------------------------------------------------------------------- 1 | # uni_translate_client 2 | 3 | A universal translate client. 4 | 5 | [![pub version][pub-image]][pub-url] 6 | 7 | [pub-image]: https://img.shields.io/pub/v/uni_translate_client.svg 8 | [pub-url]: https://pub.dev/packages/uni_translate_client 9 | 10 | --- 11 | 12 | Part of [uni_translate](https://github.com/biyidev/uni_translate) 13 | -------------------------------------------------------------------------------- /packages/uni_translate_client/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:mostly_reasonable_lints/analysis_options.yaml 2 | -------------------------------------------------------------------------------- /packages/uni_translate_client/build.yaml: -------------------------------------------------------------------------------- 1 | targets: 2 | $default: 3 | builders: 4 | source_gen|combining_builder: 5 | options: 6 | ignore_for_file: 7 | - require_trailing_commas -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/detect_language_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'detect_language_request.g.dart'; 4 | 5 | @JsonSerializable() 6 | class DetectLanguageRequest { 7 | const DetectLanguageRequest({ 8 | required this.texts, 9 | }); 10 | 11 | factory DetectLanguageRequest.fromJson(Map json) => 12 | _$DetectLanguageRequestFromJson(json); 13 | 14 | final List texts; 15 | 16 | Map toJson() => _$DetectLanguageRequestToJson(this); 17 | } 18 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/detect_language_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'detect_language_request.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | DetectLanguageRequest _$DetectLanguageRequestFromJson( 12 | Map json) => 13 | DetectLanguageRequest( 14 | texts: (json['texts'] as List).map((e) => e as String).toList(), 15 | ); 16 | 17 | Map _$DetectLanguageRequestToJson( 18 | DetectLanguageRequest instance) => 19 | { 20 | 'texts': instance.texts, 21 | }; 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/detect_language_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | import 'package:uni_translate_client/src/models/text_detection.dart'; 3 | 4 | part 'detect_language_response.g.dart'; 5 | 6 | @JsonSerializable() 7 | class DetectLanguageResponse { 8 | const DetectLanguageResponse({ 9 | this.detections, 10 | }); 11 | 12 | factory DetectLanguageResponse.fromJson(Map json) => 13 | _$DetectLanguageResponseFromJson(json); 14 | 15 | final List? detections; 16 | 17 | Map toJson() => _$DetectLanguageResponseToJson(this); 18 | } 19 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/detect_language_response.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'detect_language_response.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | DetectLanguageResponse _$DetectLanguageResponseFromJson( 12 | Map json) => 13 | DetectLanguageResponse( 14 | detections: (json['detections'] as List?) 15 | ?.map((e) => TextDetection.fromJson(e as Map)) 16 | .toList(), 17 | ); 18 | 19 | Map _$DetectLanguageResponseToJson( 20 | DetectLanguageResponse instance) => 21 | { 22 | 'detections': instance.detections, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/look_up_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | import 'package:uni_translate_client/src/translate_request.dart'; 3 | 4 | part 'look_up_request.g.dart'; 5 | 6 | @JsonSerializable() 7 | class LookUpRequest extends TranslateRequest { 8 | const LookUpRequest({ 9 | required super.sourceLanguage, 10 | required super.targetLanguage, 11 | required this.word, 12 | }) : super(text: word); 13 | 14 | factory LookUpRequest.fromJson(Map json) => 15 | _$LookUpRequestFromJson(json); 16 | 17 | final String word; 18 | 19 | @override 20 | Map toJson() => _$LookUpRequestToJson(this); 21 | } 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/look_up_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'look_up_request.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | LookUpRequest _$LookUpRequestFromJson(Map json) => 12 | LookUpRequest( 13 | sourceLanguage: json['sourceLanguage'] as String?, 14 | targetLanguage: json['targetLanguage'] as String?, 15 | word: json['word'] as String, 16 | ); 17 | 18 | Map _$LookUpRequestToJson(LookUpRequest instance) => 19 | { 20 | 'sourceLanguage': instance.sourceLanguage, 21 | 'targetLanguage': instance.targetLanguage, 22 | 'word': instance.word, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/look_up_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | import 'package:uni_translate_client/src/models/text_translation.dart'; 3 | import 'package:uni_translate_client/src/models/word_definition.dart'; 4 | import 'package:uni_translate_client/src/models/word_image.dart'; 5 | import 'package:uni_translate_client/src/models/word_phrase.dart'; 6 | import 'package:uni_translate_client/src/models/word_pronunciation.dart'; 7 | import 'package:uni_translate_client/src/models/word_sentence.dart'; 8 | import 'package:uni_translate_client/src/models/word_tag.dart'; 9 | import 'package:uni_translate_client/src/models/word_tense.dart'; 10 | import 'package:uni_translate_client/src/translate_response.dart'; 11 | 12 | part 'look_up_response.g.dart'; 13 | 14 | @JsonSerializable() 15 | class LookUpResponse extends TranslateResponse { 16 | const LookUpResponse({ 17 | super.translations, 18 | this.word, 19 | this.tip, 20 | this.tags, 21 | this.definitions, 22 | this.pronunciations, 23 | this.images, 24 | this.phrases, 25 | this.tenses, 26 | this.sentences, 27 | }); 28 | 29 | factory LookUpResponse.fromJson(Map json) => 30 | _$LookUpResponseFromJson(json); 31 | 32 | final String? word; // 单词 33 | final String? tip; // 提示 34 | final List? tags; // 标签 35 | final List? definitions; // 定义(基本释义) 36 | final List? pronunciations; // 发音 37 | final List? images; // 图片 38 | final List? phrases; // 短语 39 | final List? tenses; // 时态 40 | final List? sentences; // 例句 41 | 42 | @override 43 | Map toJson() => _$LookUpResponseToJson(this); 44 | } 45 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/look_up_response.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'look_up_response.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | LookUpResponse _$LookUpResponseFromJson(Map json) => 12 | LookUpResponse( 13 | translations: (json['translations'] as List?) 14 | ?.map((e) => TextTranslation.fromJson(e as Map)) 15 | .toList() ?? 16 | const [], 17 | word: json['word'] as String?, 18 | tip: json['tip'] as String?, 19 | tags: (json['tags'] as List?) 20 | ?.map((e) => WordTag.fromJson(e as Map)) 21 | .toList(), 22 | definitions: (json['definitions'] as List?) 23 | ?.map((e) => WordDefinition.fromJson(e as Map)) 24 | .toList(), 25 | pronunciations: (json['pronunciations'] as List?) 26 | ?.map((e) => WordPronunciation.fromJson(e as Map)) 27 | .toList(), 28 | images: (json['images'] as List?) 29 | ?.map((e) => WordImage.fromJson(e as Map)) 30 | .toList(), 31 | phrases: (json['phrases'] as List?) 32 | ?.map((e) => WordPhrase.fromJson(e as Map)) 33 | .toList(), 34 | tenses: (json['tenses'] as List?) 35 | ?.map((e) => WordTense.fromJson(e as Map)) 36 | .toList(), 37 | sentences: (json['sentences'] as List?) 38 | ?.map((e) => WordSentence.fromJson(e as Map)) 39 | .toList(), 40 | ); 41 | 42 | Map _$LookUpResponseToJson(LookUpResponse instance) => 43 | { 44 | 'translations': instance.translations, 45 | 'word': instance.word, 46 | 'tip': instance.tip, 47 | 'tags': instance.tags, 48 | 'definitions': instance.definitions, 49 | 'pronunciations': instance.pronunciations, 50 | 'images': instance.images, 51 | 'phrases': instance.phrases, 52 | 'tenses': instance.tenses, 53 | 'sentences': instance.sentences, 54 | }; 55 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/language_pair.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'language_pair.g.dart'; 4 | 5 | @JsonSerializable() 6 | class LanguagePair { 7 | const LanguagePair({ 8 | this.sourceLanguage, 9 | this.sourceLanguageId, 10 | this.targetLanguage, 11 | this.targetLanguageId, 12 | }); 13 | 14 | factory LanguagePair.fromJson(Map json) => 15 | _$LanguagePairFromJson(json); 16 | 17 | final String? sourceLanguage; 18 | final String? sourceLanguageId; 19 | final String? targetLanguage; 20 | final String? targetLanguageId; 21 | 22 | Map toJson() => _$LanguagePairToJson(this); 23 | } 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/language_pair.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'language_pair.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | LanguagePair _$LanguagePairFromJson(Map json) => LanguagePair( 12 | sourceLanguage: json['sourceLanguage'] as String?, 13 | sourceLanguageId: json['sourceLanguageId'] as String?, 14 | targetLanguage: json['targetLanguage'] as String?, 15 | targetLanguageId: json['targetLanguageId'] as String?, 16 | ); 17 | 18 | Map _$LanguagePairToJson(LanguagePair instance) => 19 | { 20 | 'sourceLanguage': instance.sourceLanguage, 21 | 'sourceLanguageId': instance.sourceLanguageId, 22 | 'targetLanguage': instance.targetLanguage, 23 | 'targetLanguageId': instance.targetLanguageId, 24 | }; 25 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/text_detection.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'text_detection.g.dart'; 4 | 5 | @JsonSerializable() 6 | class TextDetection { 7 | const TextDetection({ 8 | required this.detectedLanguage, 9 | required this.text, 10 | }); 11 | 12 | factory TextDetection.fromJson(Map json) => 13 | _$TextDetectionFromJson(json); 14 | 15 | final String detectedLanguage; 16 | final String text; 17 | 18 | Map toJson() => _$TextDetectionToJson(this); 19 | } 20 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/text_detection.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'text_detection.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | TextDetection _$TextDetectionFromJson(Map json) => 12 | TextDetection( 13 | detectedLanguage: json['detectedLanguage'] as String, 14 | text: json['text'] as String, 15 | ); 16 | 17 | Map _$TextDetectionToJson(TextDetection instance) => 18 | { 19 | 'detectedLanguage': instance.detectedLanguage, 20 | 'text': instance.text, 21 | }; 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/text_translation.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'text_translation.g.dart'; 4 | 5 | @JsonSerializable() 6 | class TextTranslation { 7 | const TextTranslation({ 8 | this.detectedSourceLanguage, 9 | required this.text, 10 | this.audioUrl, 11 | }); 12 | 13 | factory TextTranslation.fromJson(Map json) => 14 | _$TextTranslationFromJson(json); 15 | 16 | final String? detectedSourceLanguage; 17 | final String text; 18 | final String? audioUrl; 19 | 20 | Map toJson() => _$TextTranslationToJson(this); 21 | 22 | copyWith({ 23 | String? detectedSourceLanguage, 24 | String? text, 25 | String? audioUrl, 26 | }) { 27 | return TextTranslation( 28 | detectedSourceLanguage: 29 | detectedSourceLanguage ?? this.detectedSourceLanguage, 30 | text: text ?? this.text, 31 | audioUrl: audioUrl ?? this.audioUrl, 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/text_translation.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'text_translation.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | TextTranslation _$TextTranslationFromJson(Map json) => 12 | TextTranslation( 13 | detectedSourceLanguage: json['detectedSourceLanguage'] as String?, 14 | text: json['text'] as String, 15 | audioUrl: json['audioUrl'] as String?, 16 | ); 17 | 18 | Map _$TextTranslationToJson(TextTranslation instance) => 19 | { 20 | 'detectedSourceLanguage': instance.detectedSourceLanguage, 21 | 'text': instance.text, 22 | 'audioUrl': instance.audioUrl, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_definition.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_definition.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordDefinition { 7 | const WordDefinition({ 8 | this.type, 9 | this.name, 10 | this.values, 11 | }); 12 | 13 | factory WordDefinition.fromJson(Map json) => 14 | _$WordDefinitionFromJson(json); 15 | 16 | final String? type; 17 | final String? name; 18 | final List? values; 19 | 20 | Map toJson() => _$WordDefinitionToJson(this); 21 | } 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_definition.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_definition.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordDefinition _$WordDefinitionFromJson(Map json) => 12 | WordDefinition( 13 | type: json['type'] as String?, 14 | name: json['name'] as String?, 15 | values: 16 | (json['values'] as List?)?.map((e) => e as String).toList(), 17 | ); 18 | 19 | Map _$WordDefinitionToJson(WordDefinition instance) => 20 | { 21 | 'type': instance.type, 22 | 'name': instance.name, 23 | 'values': instance.values, 24 | }; 25 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_image.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_image.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordImage { 7 | WordImage({ 8 | required this.url, 9 | }); 10 | 11 | factory WordImage.fromJson(Map json) => 12 | _$WordImageFromJson(json); 13 | 14 | final String url; 15 | 16 | Map toJson() => _$WordImageToJson(this); 17 | } 18 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_image.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_image.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordImage _$WordImageFromJson(Map json) => WordImage( 12 | url: json['url'] as String, 13 | ); 14 | 15 | Map _$WordImageToJson(WordImage instance) => { 16 | 'url': instance.url, 17 | }; 18 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_phrase.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_phrase.g.dart'; 4 | 5 | // 常用短语/词组 6 | @JsonSerializable() 7 | class WordPhrase { 8 | WordPhrase({ 9 | required this.text, 10 | required this.translations, 11 | }); 12 | 13 | factory WordPhrase.fromJson(Map json) => 14 | _$WordPhraseFromJson(json); 15 | 16 | final String text; 17 | final List translations; 18 | 19 | Map toJson() => _$WordPhraseToJson(this); 20 | } 21 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_phrase.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_phrase.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordPhrase _$WordPhraseFromJson(Map json) => WordPhrase( 12 | text: json['text'] as String, 13 | translations: (json['translations'] as List) 14 | .map((e) => e as String) 15 | .toList(), 16 | ); 17 | 18 | Map _$WordPhraseToJson(WordPhrase instance) => 19 | { 20 | 'text': instance.text, 21 | 'translations': instance.translations, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_pronunciation.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_pronunciation.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordPronunciation { 7 | const WordPronunciation({ 8 | this.type, 9 | this.phoneticSymbol, 10 | this.audioUrl, 11 | }); 12 | 13 | factory WordPronunciation.fromJson(Map json) => 14 | _$WordPronunciationFromJson(json); 15 | 16 | final String? type; 17 | final String? phoneticSymbol; 18 | final String? audioUrl; 19 | 20 | Map toJson() => _$WordPronunciationToJson(this); 21 | } 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_pronunciation.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_pronunciation.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordPronunciation _$WordPronunciationFromJson(Map json) => 12 | WordPronunciation( 13 | type: json['type'] as String?, 14 | phoneticSymbol: json['phoneticSymbol'] as String?, 15 | audioUrl: json['audioUrl'] as String?, 16 | ); 17 | 18 | Map _$WordPronunciationToJson(WordPronunciation instance) => 19 | { 20 | 'type': instance.type, 21 | 'phoneticSymbol': instance.phoneticSymbol, 22 | 'audioUrl': instance.audioUrl, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_sentence.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_sentence.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordSentence { 7 | const WordSentence({ 8 | required this.text, 9 | required this.translations, 10 | }); 11 | 12 | factory WordSentence.fromJson(Map json) => 13 | _$WordSentenceFromJson(json); 14 | 15 | final String text; 16 | final List translations; 17 | 18 | Map toJson() => _$WordSentenceToJson(this); 19 | } 20 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_sentence.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_sentence.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordSentence _$WordSentenceFromJson(Map json) => WordSentence( 12 | text: json['text'] as String, 13 | translations: (json['translations'] as List) 14 | .map((e) => e as String) 15 | .toList(), 16 | ); 17 | 18 | Map _$WordSentenceToJson(WordSentence instance) => 19 | { 20 | 'text': instance.text, 21 | 'translations': instance.translations, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_tag.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_tag.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordTag { 7 | const WordTag({ 8 | required this.name, 9 | }); 10 | 11 | factory WordTag.fromJson(Map json) => 12 | _$WordTagFromJson(json); 13 | 14 | final String name; 15 | 16 | Map toJson() => _$WordTagToJson(this); 17 | } 18 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_tag.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_tag.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordTag _$WordTagFromJson(Map json) => WordTag( 12 | name: json['name'] as String, 13 | ); 14 | 15 | Map _$WordTagToJson(WordTag instance) => { 16 | 'name': instance.name, 17 | }; 18 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_tense.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'word_tense.g.dart'; 4 | 5 | @JsonSerializable() 6 | class WordTense { 7 | const WordTense({ 8 | this.type, 9 | this.name, 10 | this.values, 11 | }); 12 | factory WordTense.fromJson(Map json) => 13 | _$WordTenseFromJson(json); 14 | 15 | final String? type; 16 | final String? name; 17 | final List? values; 18 | 19 | Map toJson() => _$WordTenseToJson(this); 20 | } 21 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/models/word_tense.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'word_tense.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | WordTense _$WordTenseFromJson(Map json) => WordTense( 12 | type: json['type'] as String?, 13 | name: json['name'] as String?, 14 | values: 15 | (json['values'] as List?)?.map((e) => e as String).toList(), 16 | ); 17 | 18 | Map _$WordTenseToJson(WordTense instance) => { 19 | 'type': instance.type, 20 | 'name': instance.name, 21 | 'values': instance.values, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translate_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'translate_request.g.dart'; 4 | 5 | @JsonSerializable() 6 | class TranslateRequest { 7 | const TranslateRequest({ 8 | this.sourceLanguage, 9 | this.targetLanguage, 10 | required this.text, 11 | }); 12 | 13 | factory TranslateRequest.fromJson(Map json) => 14 | _$TranslateRequestFromJson(json); 15 | 16 | final String? sourceLanguage; 17 | final String? targetLanguage; 18 | final String text; 19 | 20 | Map toJson() => _$TranslateRequestToJson(this); 21 | } 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translate_request.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'translate_request.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | TranslateRequest _$TranslateRequestFromJson(Map json) => 12 | TranslateRequest( 13 | sourceLanguage: json['sourceLanguage'] as String?, 14 | targetLanguage: json['targetLanguage'] as String?, 15 | text: json['text'] as String, 16 | ); 17 | 18 | Map _$TranslateRequestToJson(TranslateRequest instance) => 19 | { 20 | 'sourceLanguage': instance.sourceLanguage, 21 | 'targetLanguage': instance.targetLanguage, 22 | 'text': instance.text, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translate_response.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:json_annotation/json_annotation.dart'; 4 | import 'package:uni_translate_client/src/models/text_translation.dart'; 5 | 6 | part 'translate_response.g.dart'; 7 | 8 | @JsonSerializable() 9 | class TranslateResponse { 10 | const TranslateResponse({ 11 | this.translations = const [], 12 | }); 13 | 14 | factory TranslateResponse.fromJson(Map json) => 15 | _$TranslateResponseFromJson(json); 16 | 17 | final List translations; 18 | 19 | Map toJson() => _$TranslateResponseToJson(this); 20 | } 21 | 22 | class StreamTranslateResponse extends TranslateResponse { 23 | StreamTranslateResponse({ 24 | List translations = const [], 25 | this.streamController, 26 | }) : _translations = translations, 27 | super(translations: []); 28 | 29 | final StreamController? streamController; 30 | 31 | List _translations; 32 | 33 | @override 34 | List get translations => _translations; 35 | 36 | set translations(List value) { 37 | _translations = value; 38 | if (streamController != null) { 39 | streamController!.add(this); 40 | } 41 | } 42 | 43 | bool get generating { 44 | if (streamController == null) { 45 | return false; 46 | } 47 | return !streamController!.isClosed; 48 | } 49 | 50 | @JsonKey( 51 | includeFromJson: false, 52 | includeToJson: false, 53 | ) 54 | EventSink get sink => streamController!.sink; 55 | 56 | @JsonKey( 57 | includeFromJson: false, 58 | includeToJson: false, 59 | ) 60 | Stream get stream => streamController!.stream; 61 | } 62 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translate_response.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'translate_response.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | TranslateResponse _$TranslateResponseFromJson(Map json) => 12 | TranslateResponse( 13 | translations: (json['translations'] as List?) 14 | ?.map((e) => TextTranslation.fromJson(e as Map)) 15 | .toList() ?? 16 | const [], 17 | ); 18 | 19 | Map _$TranslateResponseToJson(TranslateResponse instance) => 20 | { 21 | 'translations': instance.translations, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translation_engine.dart: -------------------------------------------------------------------------------- 1 | import 'package:uni_translate_client/src/detect_language_request.dart'; 2 | import 'package:uni_translate_client/src/detect_language_response.dart'; 3 | import 'package:uni_translate_client/src/look_up_request.dart'; 4 | import 'package:uni_translate_client/src/look_up_response.dart'; 5 | import 'package:uni_translate_client/src/models/language_pair.dart'; 6 | import 'package:uni_translate_client/src/translate_request.dart'; 7 | import 'package:uni_translate_client/src/translate_response.dart'; 8 | import 'package:uni_translate_client/src/translation_engine_scope.dart'; 9 | 10 | abstract class TranslationEngine { 11 | TranslationEngine({ 12 | required this.identifier, 13 | this.option, 14 | }); 15 | 16 | String get id => identifier; 17 | String get type => throw UnimplementedError(); 18 | List get supportedScopes => 19 | throw UnimplementedError(); 20 | 21 | String identifier; 22 | Map? option; 23 | bool disabled = false; 24 | 25 | Future> getSupportedLanguagePairs() { 26 | throw UnimplementedError(); 27 | } 28 | 29 | Future detectLanguage(DetectLanguageRequest request); 30 | 31 | Future lookUp(LookUpRequest request); 32 | 33 | Future translate(TranslateRequest request); 34 | 35 | Map toJson() { 36 | return { 37 | 'identifier': identifier, 38 | 'type': type, 39 | 'supportedScopes': supportedScopes.map((e) => e.name).toList(), 40 | 'disabled': disabled, 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/translation_engine_scope.dart: -------------------------------------------------------------------------------- 1 | enum TranslationEngineScope { 2 | detectLanguage, 3 | lookUp, 4 | translate, 5 | } 6 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/uni_translate_client.dart: -------------------------------------------------------------------------------- 1 | import 'package:uni_translate_client/src/translation_engine.dart'; 2 | import 'package:uni_translate_client/src/uni_translate_client_adapter.dart'; 3 | 4 | class UniTranslateClient { 5 | UniTranslateClient(this.adapter); 6 | 7 | final UniTranslateClientAdapter adapter; 8 | 9 | TranslationEngine get firstEngine { 10 | return adapter.first; 11 | } 12 | 13 | TranslationEngine use(String identifier) { 14 | return adapter.use(identifier); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/uni_translate_client_adapter.dart: -------------------------------------------------------------------------------- 1 | import 'package:uni_translate_client/src/translation_engine.dart'; 2 | 3 | class DefaultUniTranslateClientAdapter extends UniTranslateClientAdapter { 4 | DefaultUniTranslateClientAdapter(this.engines); 5 | final List engines; 6 | 7 | @override 8 | TranslationEngine get first { 9 | return engines.first; 10 | } 11 | 12 | @override 13 | TranslationEngine use(String identifier) { 14 | return engines.firstWhere((e) => e.identifier == identifier); 15 | } 16 | } 17 | 18 | abstract class UniTranslateClientAdapter { 19 | TranslationEngine get first; 20 | TranslationEngine use(String identifier); 21 | } 22 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/uni_translate_client_error.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'uni_translate_client_error.g.dart'; 4 | 5 | @JsonSerializable() 6 | class UniTranslateClientError implements Exception { 7 | UniTranslateClientError({ 8 | this.code, 9 | required this.message, 10 | }); 11 | 12 | factory UniTranslateClientError.fromJson(Map json) => 13 | _$UniTranslateClientErrorFromJson(json); 14 | 15 | final String? code; 16 | final String message; 17 | 18 | Map toJson() { 19 | return { 20 | 'code': code, 21 | 'message': message, 22 | }..removeWhere((key, value) => value == null); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/src/uni_translate_client_error.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | // ignore_for_file: require_trailing_commas 4 | 5 | part of 'uni_translate_client_error.dart'; 6 | 7 | // ************************************************************************** 8 | // JsonSerializableGenerator 9 | // ************************************************************************** 10 | 11 | UniTranslateClientError _$UniTranslateClientErrorFromJson( 12 | Map json) => 13 | UniTranslateClientError( 14 | code: json['code'] as String?, 15 | message: json['message'] as String, 16 | ); 17 | 18 | Map _$UniTranslateClientErrorToJson( 19 | UniTranslateClientError instance) => 20 | { 21 | 'code': instance.code, 22 | 'message': instance.message, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/lib/uni_translate_client.dart: -------------------------------------------------------------------------------- 1 | library uni_translate_client; 2 | 3 | export 'src/detect_language_request.dart'; 4 | export 'src/detect_language_response.dart'; 5 | export 'src/look_up_request.dart'; 6 | export 'src/look_up_response.dart'; 7 | export 'src/models/language_pair.dart'; 8 | export 'src/models/text_detection.dart'; 9 | export 'src/models/text_translation.dart'; 10 | export 'src/models/word_definition.dart'; 11 | export 'src/models/word_image.dart'; 12 | export 'src/models/word_phrase.dart'; 13 | export 'src/models/word_pronunciation.dart'; 14 | export 'src/models/word_sentence.dart'; 15 | export 'src/models/word_tag.dart'; 16 | export 'src/models/word_tense.dart'; 17 | export 'src/translate_request.dart'; 18 | export 'src/translate_response.dart'; 19 | export 'src/translation_engine.dart'; 20 | export 'src/translation_engine_scope.dart'; 21 | export 'src/uni_translate_client.dart'; 22 | export 'src/uni_translate_client_adapter.dart'; 23 | export 'src/uni_translate_client_error.dart'; 24 | -------------------------------------------------------------------------------- /packages/uni_translate_client/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: uni_translate_client 2 | description: A universal translate client. 3 | version: 0.1.7 4 | homepage: https://github.com/biyidev/uni_translate 5 | 6 | environment: 7 | sdk: ">=3.0.0 <4.0.0" 8 | 9 | dependencies: 10 | json_annotation: ^4.8.1 11 | 12 | dev_dependencies: 13 | build_runner: ^2.3.3 14 | json_serializable: ^6.7.1 15 | mostly_reasonable_lints: ^0.1.2 16 | test: ^1.0.0 -------------------------------------------------------------------------------- /packages/uni_translate_client/test/uni_translate_client_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:test/test.dart'; 2 | 3 | import 'package:uni_translate_client/uni_translate_client.dart'; 4 | 5 | void main() { 6 | test('adds one to input values', () { 7 | final client = UniTranslateClient(DefaultUniTranslateClientAdapter([])); 8 | client.firstEngine.lookUp( 9 | const LookUpRequest( 10 | sourceLanguage: 'en', 11 | targetLanguage: 'zh', 12 | word: 'hello', 13 | ), 14 | ); 15 | client.firstEngine.translate( 16 | const TranslateRequest( 17 | sourceLanguage: 'en', 18 | targetLanguage: 'zh', 19 | text: 'hello', 20 | ), 21 | ); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: uni_translate_workspace 2 | publish_to: "none" 3 | 4 | environment: 5 | sdk: '>=3.0.0 <4.0.0' 6 | 7 | dev_dependencies: 8 | melos: ^6.0.0 9 | --------------------------------------------------------------------------------