Skip to content

Commit

Permalink
wip: Add analysis_options to all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed May 25, 2024
1 parent f9e92c9 commit 89b43b3
Show file tree
Hide file tree
Showing 54 changed files with 191 additions and 172 deletions.
98 changes: 0 additions & 98 deletions analysis_options.yaml

This file was deleted.

1 change: 1 addition & 0 deletions packages/translation_engine_baidu/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
29 changes: 18 additions & 11 deletions packages/translation_engine_baidu/lib/translation_engine_baidu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ String _md5(String data) {

class BaiduTranslationEngine extends TranslationEngine {
BaiduTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyAppId,
_kEngineOptionKeyAppKey,
Expand Down Expand Up @@ -82,10 +83,13 @@ class BaiduTranslationEngine extends TranslationEngine {
},
);

var response = await http.post(uri, headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
});
final response = await http.post(
uri,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
);
Map<String, dynamic> data = json.decode(utf8.decode(response.bodyBytes));

if (data['error_code'] != null && data['error_code'] != 0) {
Expand Down Expand Up @@ -135,10 +139,13 @@ class BaiduTranslationEngine extends TranslationEngine {
},
);

var response = await http.post(uri, headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
});
final response = await http.post(
uri,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
);
Map<String, dynamic> data = json.decode(utf8.decode(response.bodyBytes));

if (data['error_code'] != null && data['error_code'] != 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_baidu/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
1 change: 1 addition & 0 deletions packages/translation_engine_caiyun/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const String _kEngineOptionKeyRequestId = 'requestId';

class CaiyunTranslationEngine extends TranslationEngine {
CaiyunTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyToken,
Expand All @@ -37,10 +37,10 @@ class CaiyunTranslationEngine extends TranslationEngine {
@override
Future<List<LanguagePair>> getSupportedLanguagePairs() {
return Future.value([
LanguagePair(sourceLanguage: 'en', targetLanguage: 'zh'),
LanguagePair(sourceLanguage: 'ja', targetLanguage: 'zh'),
LanguagePair(sourceLanguage: 'zh', targetLanguage: 'en'),
LanguagePair(sourceLanguage: 'zh', targetLanguage: 'ja'),
const LanguagePair(sourceLanguage: 'en', targetLanguage: 'zh'),
const LanguagePair(sourceLanguage: 'ja', targetLanguage: 'zh'),
const LanguagePair(sourceLanguage: 'zh', targetLanguage: 'en'),
const LanguagePair(sourceLanguage: 'zh', targetLanguage: 'ja'),
]);
}

Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_caiyun/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
1 change: 1 addition & 0 deletions packages/translation_engine_deepl/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
26 changes: 16 additions & 10 deletions packages/translation_engine_deepl/lib/translation_engine_deepl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const Map<String, String> _knownErrors = {

class DeepLTranslationEngine extends TranslationEngine {
DeepLTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyAuthKey,
];
Expand Down Expand Up @@ -73,9 +74,12 @@ class DeepLTranslationEngine extends TranslationEngine {
String host = _isDeepLFree ? 'api-free.deepl.com' : 'api.deepl.com';
var uri = Uri.https(host, '/v2/translate', queryParameters);

var response = await http.post(uri, headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8'
});
final response = await http.post(
uri,
headers: {
HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8',
},
);

String? errorMessage;

Expand All @@ -85,10 +89,12 @@ class DeepLTranslationEngine extends TranslationEngine {
if (data['translations'] != null) {
Iterable l = data['translations'] as List;
translations = l
.map((e) => TextTranslation(
detectedSourceLanguage: e['detected_source_language'],
text: e['text'],
))
.map(
(e) => TextTranslation(
detectedSourceLanguage: e['detected_source_language'],
text: e['text'],
),
)
.toList();
}

Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_deepl/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
1 change: 1 addition & 0 deletions packages/translation_engine_google/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const String _kEngineOptionKeyApiKey = 'apiKey';

class GoogleTranslationEngine extends TranslationEngine {
GoogleTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyApiKey,
Expand Down Expand Up @@ -71,7 +71,7 @@ class GoogleTranslationEngine extends TranslationEngine {
)
.toList();
} catch (error) {
print(error);
throw UniTranslateClientError(message: 'Failed to parse detections');
}

return DetectLanguageResponse(
Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_google/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ String _base64(String data) {

class IBMWatsonTranslationEngine extends TranslationEngine {
IBMWatsonTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyApiKey,
Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_ibmwatson/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
1 change: 1 addition & 0 deletions packages/translation_engine_iciba/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const String _kEngineOptionKeyApiKey = 'apiKey';

class IcibaTranslationEngine extends TranslationEngine {
IcibaTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyApiKey,
Expand Down Expand Up @@ -101,9 +101,11 @@ class IcibaTranslationEngine extends TranslationEngine {
audioUrl: symbol['ph_am_mp3'],
),
]
.where((e) =>
(e.phoneticSymbol ?? '').isNotEmpty ||
(e.audioUrl ?? '').isNotEmpty)
.where(
(e) =>
(e.phoneticSymbol ?? '').isNotEmpty ||
(e.audioUrl ?? '').isNotEmpty,
)
.toList();
}

Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_iciba/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
1 change: 1 addition & 0 deletions packages/translation_engine_openai/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const String _kDefaultPrompt =

class OpenAITranslationEngine extends TranslationEngine {
OpenAITranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeyBaseUrl,
Expand Down Expand Up @@ -86,7 +86,7 @@ class OpenAITranslationEngine extends TranslationEngine {
request.text,
),
],
)
),
],
);

Expand All @@ -95,7 +95,7 @@ class OpenAITranslationEngine extends TranslationEngine {
(streamChatCompletion) {
final content = streamChatCompletion.choices.first.delta.content;
if (content == null || content.isEmpty) return;
translatedText += content.first.text!;
translatedText += content.first?.text ?? '';

final textTranslation = TextTranslation(text: translatedText);
if (translateResponse.translations.isEmpty) {
Expand Down
5 changes: 4 additions & 1 deletion packages/translation_engine_openai/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
dart_openai: ^5.0.0
dart_openai: ^5.1.0
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
1 change: 1 addition & 0 deletions packages/translation_engine_tencent/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ String _signature(String key, String data) {

class TencentTranslationEngine extends TranslationEngine {
TencentTranslationEngine({
required String identifier,
Map<String, dynamic>? option,
}) : super(identifier: identifier, option: option);
required super.identifier,
super.option,
});

static List<String> optionKeys = [
_kEngineOptionKeySecretId,
Expand Down
1 change: 1 addition & 0 deletions packages/translation_engine_tencent/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
uni_translate_client: ^0.1.3

dev_dependencies:
mostly_reasonable_lints: ^0.1.2
test: ^1.0.0
Loading

0 comments on commit 89b43b3

Please sign in to comment.