Skip to content

Commit

Permalink
style: update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne Liang committed Feb 6, 2024
1 parent b7415d1 commit beb9bdb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 55 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Translate Hub
<h1 align="center">
Translate Hub
</h1>

<div align="center">
Utilize the translation API or AI capabilities on the cloud platform, combined with the Alfred workflow, to achieve rapid translation and enhance your work efficiency.

[![code style](https://antfu.me/badge-code-style.svg)](https://github.com/antfu/eslint-config) [![Alfy](https://img.shields.io/badge/Alfy-Sindre%20Sorhus-blue?color=black)](https://github.com/sindresorhus/alfy)

</div>

**English** | [中文](./README.zh-CN.md)

## Installation
Expand Down
21 changes: 11 additions & 10 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import antfu from '@antfu/eslint-config'

export default antfu({
typescript: true,
ignores: [
'*.sh',
'node_modules',
'.vscode',
'lib/**/*',
'public',
],
})
export default antfu(
{
typescript: true,
ignores: ['*.sh', 'node_modules', '.vscode', 'lib', 'public']
},
{
rules: {
'style/comma-dangle': ['error', 'never']
}
}
)
80 changes: 40 additions & 40 deletions lib/esm/alimt/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { env } from 'node:process';
import Client, { TranslateGeneralRequest } from '@alicloud/alimt20181012';
import * as $OpenApi from '@alicloud/openapi-client';
import * as $Util from '@alicloud/tea-util';
import alfy from 'alfy';
let client;
import { env } from 'node:process'
import Client, { TranslateGeneralRequest } from '@alicloud/alimt20181012'
import * as $OpenApi from '@alicloud/openapi-client'
import * as $Util from '@alicloud/tea-util'
import alfy from 'alfy'
let client
/**
* use AK&SK create Client
* @param accessKeyId
Expand All @@ -12,41 +12,41 @@ let client;
* @throws Exception
*/
function createClient(accessKeyId, accessKeySecret) {
const config = new $OpenApi.Config({
// required, your AccessKey ID
accessKeyId,
// required, your AccessKey Secret
accessKeySecret
});
// Endpoint please reference https://api.aliyun.com/product/alimt
config.endpoint = `mt.aliyuncs.com`;
return new Client.default(config);
const config = new $OpenApi.Config({
// required, your AccessKey ID
accessKeyId,
// required, your AccessKey Secret
accessKeySecret
})
// Endpoint please reference https://api.aliyun.com/product/alimt
config.endpoint = `mt.aliyuncs.com`
const ClientDefault = Client.default
return new ClientDefault(config)
}
export async function doTranslate(params) {
if (!client) {
if (!env.ALIBABA_CLOUD_ACCESS_KEY_ID || !env.ALIBABA_CLOUD_ACCESS_KEY_SECRET) {
alfy.log('Please set up your access key id and access key secret');
return;
}
// Please ensure that the environment variable is set for the code running environment ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// Engineering code leakage may lead to AccessKey leakage and threaten the security of all resources under the account. The following code example uses the environment variable to obtain the AccessKey. It is for reference only. It is recommended to use the more secure STS method. For more authentication access methods, see:https://help.aliyun.com/document_detail/378664.html
client = createClient(env.ALIBABA_CLOUD_ACCESS_KEY_ID, env.ALIBABA_CLOUD_ACCESS_KEY_SECRET);
}
const translateGeneralRequest = new TranslateGeneralRequest({});
translateGeneralRequest.formatType = 'text';
translateGeneralRequest.sourceLanguage = params.sourceLanguage || 'auto';
translateGeneralRequest.targetLanguage = params.targetLanguage;
translateGeneralRequest.sourceText = params.sourceText;
translateGeneralRequest.scene = 'general';
const runtime = new $Util.RuntimeOptions({});
try {
const res = await client?.translateGeneralWithOptions(translateGeneralRequest, runtime);
return res;
}
catch (error) {
// error message
console.error(error.message);
// Diagnostic Address
console.error(error.data.Recommend);
if (!client) {
if (!env.ALIBABA_CLOUD_ACCESS_KEY_ID || !env.ALIBABA_CLOUD_ACCESS_KEY_SECRET) {
alfy.log('Please set up your access key id and access key secret')
return
}
// Please ensure that the environment variable is set for the code running environment ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// Engineering code leakage may lead to AccessKey leakage and threaten the security of all resources under the account. The following code example uses the environment variable to obtain the AccessKey. It is for reference only. It is recommended to use the more secure STS method. For more authentication access methods, see:https://help.aliyun.com/document_detail/378664.html
client = createClient(env.ALIBABA_CLOUD_ACCESS_KEY_ID, env.ALIBABA_CLOUD_ACCESS_KEY_SECRET)
}
const translateGeneralRequest = new TranslateGeneralRequest({})
translateGeneralRequest.formatType = 'text'
translateGeneralRequest.sourceLanguage = params.sourceLanguage || 'auto'
translateGeneralRequest.targetLanguage = params.targetLanguage
translateGeneralRequest.sourceText = params.sourceText
translateGeneralRequest.scene = 'general'
const runtime = new $Util.RuntimeOptions({})
try {
const res = await client?.translateGeneralWithOptions(translateGeneralRequest, runtime)
return res
} catch (error) {
// error message
console.error(error.message)
// Diagnostic Address
console.error(error.data.Recommend)
}
}
2 changes: 1 addition & 1 deletion lib/esm/types/alimt/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion readme.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Translate Hub
<h1 align="center">
Translate Hub
</h1>

<div align="center">
利用云平台上的翻译 API 或 AI 功能,结合 Alfred 工作流程,实现快速翻译,提升您的工作效率。

[![code style](https://antfu.me/badge-code-style.svg)](https://github.com/antfu/eslint-config) [![Alfy](https://img.shields.io/badge/Alfy-Sindre%20Sorhus-blue?color=black)](https://github.com/sindresorhus/alfy)

</div>

[English](./README.md) | **中文**

## 安装
Expand Down
7 changes: 5 additions & 2 deletions src/alimt/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { env } from 'node:process'
import Client, { TranslateGeneralRequest } from '@alicloud/alimt20181012'
import type { TranslateGeneralRequest as TranslateGeneralRequestType, TranslateGeneralResponse } from '@alicloud/alimt20181012'
import type {
TranslateGeneralRequest as TranslateGeneralRequestType,
TranslateGeneralResponse
} from '@alicloud/alimt20181012'
import * as $OpenApi from '@alicloud/openapi-client'
import * as $Util from '@alicloud/tea-util'
import alfy from 'alfy'
Expand All @@ -19,7 +22,7 @@ function createClient(accessKeyId: string, accessKeySecret: string) {
// required, your AccessKey ID
accessKeyId,
// required, your AccessKey Secret
accessKeySecret,
accessKeySecret
})
// Endpoint please reference https://api.aliyun.com/product/alimt
config.endpoint = `mt.aliyuncs.com`
Expand Down

0 comments on commit beb9bdb

Please sign in to comment.