Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mololab
GitHub Repository: mololab/json-translator
Path: blob/master/src/utils/console.ts
235 views
1
import { translationModuleKeys } from '../modules/helpers';
2
import { current_version, fallbacks } from './micro';
3
var figlet = require('figlet');
4
5
const cli_name = 'jsontt';
6
7
const default_color = '\x1b[0m';
8
const success_color = '\x1b[32m';
9
const error_color = '\x1b[31m';
10
const info_color = '\x1b[34m';
11
const warn_color = '\x1b[33m';
12
13
export function success(message: string) {
14
console.log(success_color, `${message}`, default_color);
15
}
16
17
export function error(message: string) {
18
console.log(error_color, `${message}`, default_color);
19
}
20
21
export function info(message: string) {
22
console.log(info_color, `${message}`, default_color);
23
}
24
25
export function warn(message: string) {
26
console.log(warn_color, `${message}`, default_color);
27
}
28
29
export const commands = {
30
help1: '--help',
31
help2: '-h',
32
};
33
34
export const supportedLanguagesUrl = `\nsupported Languages: ${info_color}https://github.com/mololab/json-translator/blob/master/docs/LANGUAGES.md${default_color}\n`;
35
36
export const messages = {
37
cli: {
38
// cli general messages
39
welcome: `\n${warn_color}Sponsored by fotogram.ai - Transform Your Selfies into Masterpieces with AI \nhttps://fotogram.ai \n\n${default_color}Welcome to the\n${success_color +
40
figlet.textSync(
41
'jsontt'
42
)}${default_color}\n\t\t\t\tcli ${current_version}\n`,
43
description:
44
'This CLI will provide you the ability to translate your JSON/YAML files or JSON objects into different languages for free.',
45
usage: `<your/path/to/file.json>`,
46
usage_with_proxy: `Usage with proxy list file (only supported for Google module): ${cli_name} <your/path/to/file.json> <your/path/to/proxy_list.txt>`,
47
usage_by_ops: `Usage with options: ${cli_name} <your/path/to/file.json> --module <TranslationModules> --from <Language> --to <Languages...>`,
48
paths:
49
'required json file path <path/file.json> or json file with proxy list txt file path <your/path/to/file.json> <your/path/to/proxy_list.txt>',
50
51
// cli usage messages
52
module: 'specify translation module | e.g., -m google',
53
from: 'from language | e.g., -f en',
54
to: 'to translates | e.g., -t ar fr zh-CN',
55
new_file_name: 'optional ↵ | output filename | e.g., -n myApp',
56
cache_enabled: `optional ↵ | enabled cache | yes, no | default: no`,
57
fallback:
58
'optional ↵ | fallback logic, try other translation modules on fail | yes, no | default: no | e.g., -f yes',
59
concurrency_limit:
60
'optional ↵ | set max concurrency limit (higher faster, but easy to get banned) | default: 3 | e.g., -cl 5',
61
62
// cli prompt messages
63
select_module_message: 'Select translation module:',
64
from_message: 'From which language?',
65
to_message:
66
'To which language | languages? (Can select more than one with space bar)',
67
new_file_name_message: 'optional ↵ | Output filename',
68
fallback_message:
69
'optional ↵ | fallback logic, try other translation modules when fail | yes, no | default: no',
70
concurrency_limit_message:
71
'optional ↵ | set max concurrency limit (higher faster, but easy to get banned) | default: 3',
72
73
// fail messages
74
module_not_available: `module is not available. (choices : ${translationModuleKeys})`,
75
from_not_available: `translate language from is not available\n${supportedLanguagesUrl}`,
76
to_not_available: `languages to translate into is not available\n${supportedLanguagesUrl}`,
77
no_selected_language:
78
'You didn`t select any language. Please try it again and select languages with the space bar.',
79
fallback_not_available: `fallback input is not available. (choices : ${Object.keys(
80
fallbacks
81
)})`,
82
proxy_file_notValid_or_not_empty_options: `
83
- Please ensure that the value for the option "-m, --module <Translation>" is compatible
84
- Please ensure that the value for the option "-f, --from <Language>" is compatible
85
- Please ensure that the value for the option "-t, --to <Languages...>" is compatible
86
- Please ensure that the value for the option "-n, --name <string>" is valid
87
- Please ensure that the value for the option "-f, --fallback <string>" is valid
88
- Please ensure that the value for the option "-cl, --concurrencylimit <number>" is valid
89
- Please make sure to provide a valid path for the proxy list file at "<your/path/to/proxy_list.txt>".
90
`,
91
92
// success messages
93
creation_done:
94
'All files are created! You can find them in the same folder as the original file.',
95
},
96
object: {},
97
file: {
98
no_path: `The path is not provided.`,
99
no_file_in_path: `Could not find the file in the path.`,
100
cannot_translate: `Could not translate the file.`,
101
cannot_save_file: `Could not save the file.`,
102
},
103
};
104
105