File tree Expand file tree Collapse file tree 3 files changed +15
-21
lines changed
plugins/fetch/pontx-meta-fetch-plugin/src Expand file tree Collapse file tree 3 files changed +15
-21
lines changed Original file line number Diff line number Diff line change 1
1
# CHANGELOG
2
2
3
3
## 2023-06-06
4
- 1 . FEAT: ` pontx-config.json ` new parameters ` plugins.fetch.options.translate.translateCacheDir ` ,Caching translation results
4
+ 1 . FEAT: ` pontx-config.json ` new parameters ` plugins.fetch.options.translate.cacheFilePath ` ,Caching translation results
5
5
6
6
## 2023-06-03
7
7
1 . FIX: update baidu translate lib
Original file line number Diff line number Diff line change @@ -5,26 +5,17 @@ import * as os from "os";
5
5
class LocalDictManager {
6
6
static singleInstance = null as LocalDictManager ;
7
7
8
- static getSingleInstance ( options = { } , configDir = "" ) {
8
+ static getSingleInstance ( localDictDir ) {
9
9
if ( ! LocalDictManager . singleInstance ) {
10
- LocalDictManager . singleInstance = new LocalDictManager ( options , configDir ) ;
10
+ LocalDictManager . singleInstance = new LocalDictManager ( localDictDir ) ;
11
11
return LocalDictManager . singleInstance ;
12
12
}
13
13
14
14
return LocalDictManager . singleInstance ;
15
15
}
16
16
17
- private localDictDir = os . homedir ( ) + "/.pont" ;
18
-
19
- constructor ( options , configDir ) {
20
- if ( options ?. translateCacheDir ) {
21
- this . localDictDir = path . join ( configDir , options ?. translateCacheDir ) ;
22
- if ( ! fs . pathExistsSync ( this . localDictDir ) ) {
23
- fs . mkdirpSync ( this . localDictDir ) ;
24
- }
25
- return ;
26
- }
27
- if ( ! fs . pathExistsSync ( this . localDictDir ) ) {
17
+ constructor ( private localDictDir = "" ) {
18
+ if ( this . localDictDir && ! fs . pathExistsSync ( this . localDictDir ) ) {
28
19
fs . mkdirpSync ( this . localDictDir ) ;
29
20
}
30
21
}
Original file line number Diff line number Diff line change 1
- import { fetch } from "node-fetch" ;
1
+ import * as os from "os" ;
2
+ import * as path from "path" ;
2
3
import * as _ from "lodash" ;
3
4
const { youdao, baidu, google } = require ( "translation.js" ) ;
4
5
import * as assert from "assert" ;
@@ -62,13 +63,15 @@ export class Translate {
62
63
dict = { } ;
63
64
64
65
constructor ( private logger , private translateOptions : any = { } , private config : any = { } ) {
65
- this . PontDictManager = PontDictManager (
66
- this . translateOptions ,
67
- this . config ?. plugins ?. fetch ?. instance ?. innerConfig ?. configDir ,
68
- ) ;
69
- if ( translateOptions ?. translateCacheDir ) {
70
- this . dictName = "pontxTranslateCache.json" ;
66
+ let localDictDir = os . homedir ( ) + "/.pont" ;
67
+ if ( translateOptions ?. cacheFilePath ) {
68
+ this . dictName = path . basename ( translateOptions ?. cacheFilePath ) ;
69
+ localDictDir = path . resolve (
70
+ this . config ?. plugins ?. fetch ?. instance ?. innerConfig ?. configDir ,
71
+ path . dirname ( translateOptions . cacheFilePath ) ,
72
+ ) ;
71
73
}
74
+ this . PontDictManager = PontDictManager ( localDictDir ) ;
72
75
const localDict = this . PontDictManager . loadFileIfExistsSync ( this . dictName ) ;
73
76
74
77
if ( localDict ) {
You can’t perform that action at this time.
0 commit comments