@yxw007/translate 0.0.1-alpha.2 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/README_zh-CN.md +48 -15
- package/dist/{index.cjs → browser/index.cjs} +6 -1
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.min.cjs +2 -0
- package/dist/browser/index.min.cjs.map +1 -0
- package/dist/{index.umd.js → browser/index.umd.js} +6 -1
- package/dist/{index.cjs.map → browser/index.umd.js.map} +1 -1
- package/dist/browser/index.umd.min.js +2 -0
- package/dist/browser/index.umd.min.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/node/index.cjs +13497 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.js +13490 -0
- package/dist/node/index.js.map +1 -0
- package/dist/package.json +16 -5
- package/package.json +16 -5
- package/dist/index.js +0 -6849
- package/dist/index.js.map +0 -1
- package/dist/index.umd.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// translate v0.0.1 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
|
|
1
2
|
(function (global, factory) {
|
|
2
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -6822,7 +6823,7 @@ ${toHex(hashedRequest)}`;
|
|
|
6822
6823
|
this.engines.set(engine.name, engine);
|
|
6823
6824
|
}
|
|
6824
6825
|
translate(text, options) {
|
|
6825
|
-
const { from, to, engine = "google", cache_time = 60 } = options;
|
|
6826
|
+
const { from, to, engine = "google", cache_time = 60 * 1000 } = options;
|
|
6826
6827
|
//1. Check if engine exists
|
|
6827
6828
|
if (!this.engines.has(engine)) {
|
|
6828
6829
|
throw new Error(`Engine ${engine} not found`);
|
|
@@ -6835,6 +6836,10 @@ ${toHex(hashedRequest)}`;
|
|
|
6835
6836
|
throw new Error(`Language ${to} not found`);
|
|
6836
6837
|
}
|
|
6837
6838
|
const key = `${from}:${to}:${engine}:${text}`;
|
|
6839
|
+
//3. If the cache is matched, the cache is used directly
|
|
6840
|
+
if (cache.get(key)) {
|
|
6841
|
+
return cache.get(key)?.value;
|
|
6842
|
+
}
|
|
6838
6843
|
const engineInstance = this.engines.get(engine);
|
|
6839
6844
|
if (!engineInstance) {
|
|
6840
6845
|
throw new Error(`Engine ${engine} not found`);
|