-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ node_modules/ | |
|
||
yarn.lock | ||
package-lock.json | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 在使用此示例前,请先将文件名'example'去掉 | ||
|
||
# 端口号 | ||
# type: Number | ||
PORT=6119 | ||
|
||
# 是否允许请求备选翻译 | ||
# type: Boolean | ||
ALTERNATIVE=true | ||
|
||
# 跨域请求 (待完善) | ||
# type: Boolean String RegExp | ||
# 正则表达式请使用引号包裹。 | ||
# 示例: '*'(允许任何) 或者 false(不允许) | ||
CORS_ORIGIN=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
import { translate } from './translate.js'; | ||
|
||
(async () => { | ||
// Example Call | ||
await translate('各位评委好,我是练习时长两年半的个人练习生,蔡徐坤', 'ZH', 'EN', 3, true); | ||
console.log('\n'); | ||
})() | ||
/** | ||
* 一个示例调用,用于非http协议的服务内调用 | ||
* 你可以在其他js中调用,无需运行 'npm start' | ||
* 如果无需在控制台打印,最后一个布尔值参数可以去掉 | ||
* | ||
* @async | ||
* @param {string} text - 待翻译的文本 | ||
* @param {string} [sourceLang='AUTO'] - 源语言国家/地区代号 默认自动识别 | ||
* @param {string} targetLang - 目标语言国家/地区代号 | ||
* @param {number} [alternativeCount] - 请求的备选翻译数量 | ||
* @param {boolean} [printResult] - 控制台打印返回结果 | ||
* @returns {Promise<Object>} translationData - 返回翻译数据JSON对象 | ||
* @typedef {Object} translationData | ||
* @property {number} code - http状态码 | ||
* @property {string} data - 翻译结果 | ||
* @property {number} id | ||
* @property {string} method - 请求的接口类型 目前只有Free | ||
* @property {string} source_lang - 源语言国家/地区代号 | ||
* @property {string} target_lang - 目标语言国家/地区代号 | ||
* @property {Array<string>} alternatives - 备选翻译列表 | ||
*/ | ||
await translate('你好,世界!', 'zh', 'en', 3, true); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters