auto-translate-json-library 1.1.5 → 1.2.0

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/config.d.ts CHANGED
@@ -1,33 +1,37 @@
1
- export declare type Configuration = {
2
- translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey;
3
- startDelimiter: string;
4
- endDelimiter: string;
5
- mode: 'file' | 'folder';
6
- sourceLocale: string;
7
- keepTranslations: 'keep' | 'retranslate';
8
- keepExtraTranslations: 'keep' | 'remove';
9
- };
10
- declare type GoogleTranslationKey = {
11
- kind: 'google';
12
- apiKey: string;
13
- };
14
- declare type AwsTranslationKey = {
15
- kind: 'aws';
16
- accessKeyId: string;
17
- secretAccessKey: string;
18
- region: string;
19
- };
20
- declare type AzureTranslationKey = {
21
- kind: 'azure';
22
- secretKey: string;
23
- region: string;
24
- };
25
- declare type DeepLProTranslationKey = {
26
- kind: 'deepLPro';
27
- secretKey: string;
28
- };
29
- declare type DeepLFreeTranslationKey = {
30
- kind: 'deepLFree';
31
- secretKey: string;
32
- };
33
- export {};
1
+ export type Configuration = {
2
+ translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey | OpenAITranslationKey;
3
+ startDelimiter: string;
4
+ endDelimiter: string;
5
+ mode: 'file' | 'folder';
6
+ sourceLocale: string;
7
+ keepTranslations: 'keep' | 'retranslate';
8
+ keepExtraTranslations: 'keep' | 'remove';
9
+ };
10
+ type GoogleTranslationKey = {
11
+ kind: 'google';
12
+ apiKey: string;
13
+ };
14
+ type AwsTranslationKey = {
15
+ kind: 'aws';
16
+ accessKeyId: string;
17
+ secretAccessKey: string;
18
+ region: string;
19
+ };
20
+ type AzureTranslationKey = {
21
+ kind: 'azure';
22
+ secretKey: string;
23
+ region: string;
24
+ };
25
+ type DeepLProTranslationKey = {
26
+ kind: 'deepLPro';
27
+ secretKey: string;
28
+ };
29
+ type DeepLFreeTranslationKey = {
30
+ kind: 'deepLFree';
31
+ secretKey: string;
32
+ };
33
+ type OpenAITranslationKey = {
34
+ kind: 'openai';
35
+ apiKey: string;
36
+ };
37
+ export {};
package/config.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/deepl.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { ITranslate } from './translate.interface';
2
- export declare class DeepLTranslate implements ITranslate {
3
- private subscriptionKey;
4
- private type;
5
- private endpoint;
6
- constructor(subscriptionKey: string, type: 'free' | 'pro');
7
- isValidLocale(targetLocale: string): boolean;
8
- translateText(text: string, sourceLocale: string, targetLocale: string): Promise<string>;
9
- }
1
+ import { ITranslate } from './translate.interface';
2
+ export declare class DeepLTranslate implements ITranslate {
3
+ private subscriptionKey;
4
+ private type;
5
+ private endpoint;
6
+ constructor(subscriptionKey: string, type: 'free' | 'pro');
7
+ isValidLocale(targetLocale: string): boolean;
8
+ translateText(text: string, sourceLocale: string, targetLocale: string): Promise<string>;
9
+ }
package/deepl.js CHANGED
@@ -1,82 +1,82 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DeepLTranslate = void 0;
13
- const FormData = require("form-data");
14
- const axios = require('axios').default;
15
- const util_1 = require("./util");
16
- const supportedLanguages = [
17
- 'BG',
18
- 'CS',
19
- 'DA',
20
- 'DE',
21
- 'EL',
22
- 'EN-GB',
23
- 'EN-US',
24
- 'EN',
25
- 'ES',
26
- 'ET',
27
- 'FI',
28
- 'FR',
29
- 'HU',
30
- 'IT',
31
- 'JA',
32
- 'LT',
33
- 'LV',
34
- 'NL',
35
- 'PL',
36
- 'PT-PT',
37
- 'PT-BR',
38
- 'PT',
39
- 'RO',
40
- 'RU',
41
- 'SK',
42
- 'SL',
43
- 'SV',
44
- 'ZH'
45
- ];
46
- class DeepLTranslate {
47
- constructor(subscriptionKey, type) {
48
- this.subscriptionKey = subscriptionKey;
49
- this.type = type;
50
- this.endpoint = 'https://api.deepl.com';
51
- if (this.type === 'free') {
52
- this.endpoint = 'https://api.free.deepl.com';
53
- }
54
- }
55
- isValidLocale(targetLocale) {
56
- return supportedLanguages.includes(targetLocale.toUpperCase());
57
- }
58
- translateText(text, sourceLocale, targetLocale) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- let args;
61
- ({ args, text } = util_1.Util.replaceContextVariables(text));
62
- let result = '';
63
- const formData = new FormData();
64
- formData.append('auth_key', this.subscriptionKey);
65
- formData.append('text', text);
66
- formData.append('source_lang', sourceLocale.toUpperCase());
67
- formData.append('target_lang', targetLocale.toUpperCase());
68
- const response = yield axios({
69
- baseURL: this.endpoint,
70
- url: 'v2/translate',
71
- method: 'post',
72
- data: formData,
73
- responseType: 'json'
74
- });
75
- result = response.translations[1].text;
76
- result = util_1.Util.replaceArgumentsWithNumbers(args, result);
77
- return result;
78
- });
79
- }
80
- }
81
- exports.DeepLTranslate = DeepLTranslate;
82
- // https://www.deepl.com/docs-api/translating-text/example/
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeepLTranslate = void 0;
13
+ const FormData = require("form-data");
14
+ const axios = require('axios').default;
15
+ const util_1 = require("./util");
16
+ const supportedLanguages = [
17
+ 'BG',
18
+ 'CS',
19
+ 'DA',
20
+ 'DE',
21
+ 'EL',
22
+ 'EN-GB',
23
+ 'EN-US',
24
+ 'EN',
25
+ 'ES',
26
+ 'ET',
27
+ 'FI',
28
+ 'FR',
29
+ 'HU',
30
+ 'IT',
31
+ 'JA',
32
+ 'LT',
33
+ 'LV',
34
+ 'NL',
35
+ 'PL',
36
+ 'PT-PT',
37
+ 'PT-BR',
38
+ 'PT',
39
+ 'RO',
40
+ 'RU',
41
+ 'SK',
42
+ 'SL',
43
+ 'SV',
44
+ 'ZH'
45
+ ];
46
+ class DeepLTranslate {
47
+ constructor(subscriptionKey, type) {
48
+ this.subscriptionKey = subscriptionKey;
49
+ this.type = type;
50
+ this.endpoint = 'https://api.deepl.com';
51
+ if (this.type === 'free') {
52
+ this.endpoint = 'https://api.free.deepl.com';
53
+ }
54
+ }
55
+ isValidLocale(targetLocale) {
56
+ return supportedLanguages.includes(targetLocale.toUpperCase());
57
+ }
58
+ translateText(text, sourceLocale, targetLocale) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ let args;
61
+ ({ args, text } = util_1.Util.replaceContextVariables(text));
62
+ let result = '';
63
+ const formData = new FormData();
64
+ formData.append('auth_key', this.subscriptionKey);
65
+ formData.append('text', text);
66
+ formData.append('source_lang', sourceLocale.toUpperCase());
67
+ formData.append('target_lang', targetLocale.toUpperCase());
68
+ const response = yield axios({
69
+ baseURL: this.endpoint,
70
+ url: 'v2/translate',
71
+ method: 'post',
72
+ data: formData,
73
+ responseType: 'json'
74
+ });
75
+ result = response.translations[1].text;
76
+ result = util_1.Util.replaceArgumentsWithNumbers(args, result);
77
+ return result;
78
+ });
79
+ }
80
+ }
81
+ exports.DeepLTranslate = DeepLTranslate;
82
+ // https://www.deepl.com/docs-api/translating-text/example/
package/files.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- export interface IFiles {
2
- sourceLocale: string;
3
- targetLocales: Array<string>;
4
- loadJsonFromLocale(locale: string): Promise<any>;
5
- saveJsonToLocale(locale: string, file: any): void;
6
- }
7
- export declare const readFileAsync: (filename: string) => Promise<string>;
8
- export declare const loadJsonFromLocale: (fileName: string) => Promise<any>;
9
- export declare const saveJsonToLocale: (filename: string, file: any) => void;
10
- export declare class Files implements IFiles {
11
- folderPath: string;
12
- sourceLocale: string;
13
- targetLocales: Array<string>;
14
- constructor(filePath: string);
15
- private getLocaleFromFilename;
16
- private getTargetLocales;
17
- loadJsonFromLocale(locale: string): Promise<any>;
18
- saveJsonToLocale(locale: string, file: any): void;
19
- }
1
+ export interface IFiles {
2
+ sourceLocale: string;
3
+ targetLocales: Array<string>;
4
+ loadJsonFromLocale(locale: string): Promise<any>;
5
+ saveJsonToLocale(locale: string, file: any): void;
6
+ }
7
+ export declare const readFileAsync: (filename: string) => Promise<string>;
8
+ export declare const loadJsonFromLocale: (fileName: string) => Promise<any>;
9
+ export declare const saveJsonToLocale: (filename: string, file: any) => void;
10
+ export declare class Files implements IFiles {
11
+ folderPath: string;
12
+ sourceLocale: string;
13
+ targetLocales: Array<string>;
14
+ constructor(filePath: string);
15
+ private getLocaleFromFilename;
16
+ private getTargetLocales;
17
+ loadJsonFromLocale(locale: string): Promise<any>;
18
+ saveJsonToLocale(locale: string, file: any): void;
19
+ }
package/files.js CHANGED
@@ -1,88 +1,88 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Files = exports.saveJsonToLocale = exports.loadJsonFromLocale = exports.readFileAsync = void 0;
36
- const path = __importStar(require("path"));
37
- const fs = __importStar(require("fs"));
38
- const readFileAsync = (filename) => new Promise((resolve, reject) => {
39
- fs.readFile(filename, (error, data) => {
40
- error ? reject(error) : resolve(data.toString());
41
- });
42
- });
43
- exports.readFileAsync = readFileAsync;
44
- const loadJsonFromLocale = (fileName) => __awaiter(void 0, void 0, void 0, function* () {
45
- let data = yield (0, exports.readFileAsync)(fileName);
46
- // handle empty files
47
- if (!data) {
48
- data = '{}';
49
- }
50
- return JSON.parse(data);
51
- });
52
- exports.loadJsonFromLocale = loadJsonFromLocale;
53
- const saveJsonToLocale = (filename, file) => {
54
- let data = JSON.stringify(file, null, ' ');
55
- fs.writeFileSync(filename, data, 'utf8');
56
- };
57
- exports.saveJsonToLocale = saveJsonToLocale;
58
- class Files {
59
- constructor(filePath) {
60
- this.folderPath = path.dirname(filePath);
61
- let fileName = path.basename(filePath);
62
- this.sourceLocale = this.getLocaleFromFilename(fileName);
63
- this.targetLocales = this.getTargetLocales();
64
- }
65
- getLocaleFromFilename(fileName) {
66
- return fileName.replace('.json', '');
67
- }
68
- getTargetLocales() {
69
- let locales = new Array();
70
- let files = fs.readdirSync(this.folderPath);
71
- files.forEach((file) => {
72
- let locale = this.getLocaleFromFilename(file);
73
- if (locale !== this.sourceLocale) {
74
- locales.push(locale);
75
- }
76
- });
77
- return locales;
78
- }
79
- loadJsonFromLocale(locale) {
80
- let filename = this.folderPath + '/' + locale + '.json';
81
- return (0, exports.loadJsonFromLocale)(filename);
82
- }
83
- saveJsonToLocale(locale, file) {
84
- let filename = this.folderPath + '/' + locale + '.json';
85
- (0, exports.saveJsonToLocale)(filename, file);
86
- }
87
- }
88
- exports.Files = Files;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Files = exports.saveJsonToLocale = exports.loadJsonFromLocale = exports.readFileAsync = void 0;
36
+ const path = __importStar(require("path"));
37
+ const fs = __importStar(require("fs"));
38
+ const readFileAsync = (filename) => new Promise((resolve, reject) => {
39
+ fs.readFile(filename, (error, data) => {
40
+ error ? reject(error) : resolve(data.toString());
41
+ });
42
+ });
43
+ exports.readFileAsync = readFileAsync;
44
+ const loadJsonFromLocale = (fileName) => __awaiter(void 0, void 0, void 0, function* () {
45
+ let data = yield (0, exports.readFileAsync)(fileName);
46
+ // handle empty files
47
+ if (!data) {
48
+ data = '{}';
49
+ }
50
+ return JSON.parse(data);
51
+ });
52
+ exports.loadJsonFromLocale = loadJsonFromLocale;
53
+ const saveJsonToLocale = (filename, file) => {
54
+ let data = JSON.stringify(file, null, ' ');
55
+ fs.writeFileSync(filename, data, 'utf8');
56
+ };
57
+ exports.saveJsonToLocale = saveJsonToLocale;
58
+ class Files {
59
+ constructor(filePath) {
60
+ this.folderPath = path.dirname(filePath);
61
+ let fileName = path.basename(filePath);
62
+ this.sourceLocale = this.getLocaleFromFilename(fileName);
63
+ this.targetLocales = this.getTargetLocales();
64
+ }
65
+ getLocaleFromFilename(fileName) {
66
+ return fileName.replace('.json', '');
67
+ }
68
+ getTargetLocales() {
69
+ let locales = new Array();
70
+ let files = fs.readdirSync(this.folderPath);
71
+ files.forEach((file) => {
72
+ let locale = this.getLocaleFromFilename(file);
73
+ if (locale !== this.sourceLocale) {
74
+ locales.push(locale);
75
+ }
76
+ });
77
+ return locales;
78
+ }
79
+ loadJsonFromLocale(locale) {
80
+ let filename = this.folderPath + '/' + locale + '.json';
81
+ return (0, exports.loadJsonFromLocale)(filename);
82
+ }
83
+ saveJsonToLocale(locale, file) {
84
+ let filename = this.folderPath + '/' + locale + '.json';
85
+ (0, exports.saveJsonToLocale)(filename, file);
86
+ }
87
+ }
88
+ exports.Files = Files;
package/folderFiles.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { IFiles } from './files';
2
- export declare class FolderFiles implements IFiles {
3
- folderPath: string;
4
- sourceLocale: string;
5
- targetLocales: Array<string>;
6
- fileName: string;
7
- constructor(filePath: string);
8
- private getTargetLocales;
9
- private createFileName;
10
- loadJsonFromLocale(locale: string): Promise<any>;
11
- saveJsonToLocale(locale: string, file: any): void;
12
- }
1
+ import { IFiles } from './files';
2
+ export declare class FolderFiles implements IFiles {
3
+ folderPath: string;
4
+ sourceLocale: string;
5
+ targetLocales: Array<string>;
6
+ fileName: string;
7
+ constructor(filePath: string);
8
+ private getTargetLocales;
9
+ private createFileName;
10
+ loadJsonFromLocale(locale: string): Promise<any>;
11
+ saveJsonToLocale(locale: string, file: any): void;
12
+ }
package/folderFiles.js CHANGED
@@ -1,57 +1,57 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.FolderFiles = void 0;
27
- const path = __importStar(require("path"));
28
- const fs = __importStar(require("fs"));
29
- const files_1 = require("./files");
30
- class FolderFiles {
31
- constructor(filePath) {
32
- const localeDir = path.dirname(filePath);
33
- this.folderPath = path.dirname(localeDir);
34
- this.fileName = path.basename(filePath);
35
- this.sourceLocale = path.basename(localeDir);
36
- this.targetLocales = this.getTargetLocales();
37
- console.log(this.folderPath, this.fileName, this.sourceLocale, this.targetLocales);
38
- }
39
- getTargetLocales() {
40
- let files = fs
41
- .readdirSync(this.folderPath)
42
- .map((folder) => path.basename(folder))
43
- .map((locale) => (locale !== this.sourceLocale ? locale : ''))
44
- .filter((x) => x); // do not want empty strings
45
- return files;
46
- }
47
- createFileName(locale) {
48
- return `${this.folderPath}/${locale}/${this.fileName}`;
49
- }
50
- loadJsonFromLocale(locale) {
51
- return (0, files_1.loadJsonFromLocale)(this.createFileName(locale));
52
- }
53
- saveJsonToLocale(locale, file) {
54
- (0, files_1.saveJsonToLocale)(this.createFileName(locale), file);
55
- }
56
- }
57
- exports.FolderFiles = FolderFiles;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.FolderFiles = void 0;
27
+ const path = __importStar(require("path"));
28
+ const fs = __importStar(require("fs"));
29
+ const files_1 = require("./files");
30
+ class FolderFiles {
31
+ constructor(filePath) {
32
+ const localeDir = path.dirname(filePath);
33
+ this.folderPath = path.dirname(localeDir);
34
+ this.fileName = path.basename(filePath);
35
+ this.sourceLocale = path.basename(localeDir);
36
+ this.targetLocales = this.getTargetLocales();
37
+ console.log(this.folderPath, this.fileName, this.sourceLocale, this.targetLocales);
38
+ }
39
+ getTargetLocales() {
40
+ let files = fs
41
+ .readdirSync(this.folderPath)
42
+ .map((folder) => path.basename(folder))
43
+ .map((locale) => (locale !== this.sourceLocale ? locale : ''))
44
+ .filter((x) => x); // do not want empty strings
45
+ return files;
46
+ }
47
+ createFileName(locale) {
48
+ return `${this.folderPath}/${locale}/${this.fileName}`;
49
+ }
50
+ loadJsonFromLocale(locale) {
51
+ return (0, files_1.loadJsonFromLocale)(this.createFileName(locale));
52
+ }
53
+ saveJsonToLocale(locale, file) {
54
+ (0, files_1.saveJsonToLocale)(this.createFileName(locale), file);
55
+ }
56
+ }
57
+ exports.FolderFiles = FolderFiles;
package/google.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ITranslate } from './translate.interface';
2
- export declare class GoogleTranslate implements ITranslate {
3
- private apikey;
4
- private googleTranslate;
5
- constructor(apikey: string);
6
- isValidLocale(targetLocale: string): boolean;
7
- translateText(text: string, _sourceLocale: string, targetLocale: string): Promise<string>;
8
- }
1
+ import { ITranslate } from './translate.interface';
2
+ export declare class GoogleTranslate implements ITranslate {
3
+ private apikey;
4
+ private googleTranslate;
5
+ constructor(apikey: string);
6
+ isValidLocale(targetLocale: string): boolean;
7
+ translateText(text: string, _sourceLocale: string, targetLocale: string): Promise<string>;
8
+ }