-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtrans.txt
667 lines (521 loc) · 24.3 KB
/
trans.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
*trans.txt* Translate text using translate-shell in vim.
_ _ _ _ _ _ _ ~
| | | | | | | | | | | (_) ~
| |_ _ __ __ _ _ __ ___| | __ _| |_ ___ ____ ___| |__ ___| | |_ ___ _ __ ___ ~
| __| '__/ _` | '_ \/ __| |/ _` | __/ _ \____/ __| '_ \ / _ \ | \ \ / / | '_ ` _ \ ~
| |_| | | (_| | | | \__ \ | (_| | || __/ \__ \ | | | __/ | |\ V /| | | | | | | ~
\__|_| \__,_|_| |_|___/_|\__,_|\__\___| |___/_| |_|\___|_|_(_)_/ |_|_| |_| |_| ~
Author: Egor Churaev <egor.churaev@gmail.com>
Licence: GPLv3
Homepage: https://github.com/echuraev/translate-shell.vim
Version: 2.1.0
==============================================================================
CONTENTS *trans* *translate-shell.vim* *trans-context*
1. Intro ............................ |trans-intro|
Features ......................... |trans-features|
2. Requirements ..................... |trans-requirements|
3. Installation ..................... |trans-installation|
4. Usage ............................ |trans-usage|
Commands ........................ |trans-commands|
Key mappings .................... |trans-keys|
Import history to Anki .......... |trans-Anki|
5. Configuration .................... |trans-configuration|
6. Changelog ........................ |trans-changelog|
7. Todo ............................. |trans-todo|
==============================================================================
INTRO *trans-intro*
Translate-shell.vim is a plugin for translating text without leaving Vim. It
provides a window that displays the translate of word under cursor, selected
text or you can use "on fly" translation and translate inserted text. Also,
you can save your translate story to file and import it to Anki. More
information you can find in |trans-commands|.
------------------------------------------------------------------------------
FEATURES *trans-features*
The following features are supported by translate-shell.vim:
- Translate word under cursor.
- Translate multi line string.
- Select direction of translate from predefined list.
- Interactive translation.
- Open interactive terminal with translate-shell (only Vim 8).
- Keep translate story. Choose the better translate to save.
- Download audio for translation.
- Import translation history to Anki.
==============================================================================
REQUIREMENTS *trans-requirements*
The following requirements have to be met in order to be able to use
translate-shell.vim:
- Install translate-shell. Translate-shell is used as a backend for the
plugin. You can find it on github:
https://github.com/soimort/translate-shell
Installation process is described in |trans-installation|.
Also, if you would like to use FZF functions that provided by this plugin,
you have to install it. Detailed information you can find here:
https://github.com/junegunn/fzf.vim#installation
==============================================================================
INSTALLATION *trans-installation*
You can install translate-shell.vim by using any vim plugin manager.
Installation with vim-plug:~
If you doesn't have installed translate-shell in path, you can install plugin
by the following command: >
Plug 'echuraev/translate-shell.vim', { 'do': 'wget -O ~/.vim/trans git.io/trans && chmod +x ~/.vim/trans' }
And after it you should specify path to translate-shell by defining
|g:trans_bin| variable e.g: >
let g:trans_bin = "~/.vim"
If you already have installed translate-shell in your PATH then it is enough
to install plugin by the following command: >
Plug 'echuraev/translate-shell.vim'
==============================================================================
USAGE *trans-usage*
There are several different ways to use |translate-shell.vim|:
1. Translate word under cursor (with default parameters):~
Run command |:Trans| and word under cursor will be translated. Target
language determines by using variable |g:trans_default_direction|.
Exercise (translate word): `Hello`
2. Translate visual selection (with default parameters):~
Run command |:'<,'>Trans| and word in selection will be translated. Target
language determines by using variable |g:trans_default_direction|.
Exercise (translate sentence): `Hello github world!`
3. Translate word under cursor (with parameters from command line):~
You can pass any arguments to command |:Trans|. Try to translate word from
English to German in brief mode by command: `:Trans -brief` `:de`.
Exercise (translate word): `Hello`
4. Translate visual selection (with parameters from command line):~
You can pass any arguments to command |:'<,'>Trans|. Try to translate
sentence from English to German in brief mode by command:
`:'<,'>Trans -brief` `:de`.
Exercise (translate sentence): `Hello github world!`
5. Translate word with choosing direction:~
You can translate word and choose target translation from predefined list
|g:trans_directions_list|. Just run command |:TransSelectDirection|.
Exercise (translate word): `Hello`
6. Translate visual selection with choosing direction:~
You can translate visual selection and choose target translation from
predefined list |g:trans_directions_list|. Just run command
|:'<,'>TransSelectDirection|.
Exercise (translate sentence): `Hello github world!`
7. Interactive translation (translate user input):~
You can translate anything that you wish "on fly" by using command
|:TransInteractive|. Target language determines by using variable
|g:trans_default_direction|.
Exercise: Translate something with `:TransInteractive`
8. Interactive translation (translate user input):~
You can translate anything that you wish "on fly" by using command
|:TransInteractive|. Try to pass options from command line.
Exercise: Translate something with `:TransInteractive -brief :de`
9. Translate terminal (works only in Vim 8):~
You can open terminal with translate-shell and work in it by command
|:TransTerm|. Target language determines by using variable
|g:trans_default_direction|.
Exercise: Translate something with `:TransTerm`
10. Translate terminal with parameters from command line (works only in Vim 8):~
You can open terminal with translate-shell and work in it by command
|:TransTerm|. Try to pass options from command line.
Exercise: Translate something with `:TransTerm -brief :de`
------------------------------------------------------------------------------
COMMANDS *trans-commands*
:Trans [{options}] *:Trans*
Translate word under cursor.
:{range}Trans [{options}]
Translate text in {range}.
- If you call it without any parameters it will run with default
parameters from variable |g:trans_default_direction|.
- If you pass options then variable |g:trans_default_direction| will be
ignored. For more details see section |trans-usage|.
:TransSelectDirection *:TransSelectDirection*
Gives a choice of translate direction and translate word under cursor.
Translate directions are determined in predefined list
|g:trans_directions_list|. For more details see section |trans-usage|.
:{range}TransSelectDirection
Gives a choice of translate direction and translate text in {range}.
:TransInteractive [{options}] *:TransInteractive*
Gives a choice of translate direction and translate text of user.
- If you call it without any parameters it will run with default
parameters from variable |g:trans_default_direction| or will give a
choice if list |g:trans_directions_list| is specified. You can use
variable |g:trans_interactive_full_list| if you wish to select
languages from all possible variants.
- If you pass options then variable |g:trans_default_direction| will be
ignored. For more details see section |trans-usage|.
:TransTerm [{options}] *:TransTerm*
Open terminal with interactive translate-shell. That works only in VIM 8.
- If you call it without any parameters it will run with default
parameters from variable |g:trans_default_direction|.
- If you pass options then variable |g:trans_default_direction| will be
ignored. For more details see section |trans-usage|.
:TransOpenHistoryWindow *:TransOpenHistoryWindow*
Open file with translate history. In this window you can edit the history
file. In case it there are several history files e.g.
|g:trans_save_history| has value 2 or 3, you can choose which file you
would like to open.
:TransChangeDefaultDirection *:TransChangeDefaultDirection*
You can change default direction of translating for a session by
changing vim variable |g:trans_default_direction| e.g.:
>
let g:trans_default_direction="de:en"
<
This command was added only for more comfortable changing default
translate direction. It give you choice to select languages from the list
of all available languages. And don't remember a language code.
------------------------------------------------------------------------------
FZF COMMANDS *trans-fzf-commands*
:FZFTransSelectDirection *:FZFTransSelectDirection*
Gives a choice of translate direction in fzf window and translate word
under cursor. Works in the same way as |:TransSelectDirection|.
:{range}FZFTransSelectDirection
Gives a choice of translate direction in fzf window and translate text in
{range}.
:FZFTransInteractive [{options}] *:FZFTransInteractive*
Gives a choice of translate direction in fzf window and translate text
from input. Translate directions are determined in predefined list
|g:trans_directions_list|. If you wish to select languages from all
possible variants then you should use |g:trans_interactive_full_list|
variable.
:FZFTransChangeDefaultDirection *:FZFTransChangeDefaultDirection*
Gives a choice of default translate direction in fzf window. Works in the
same way as |:TransChangeDefaultDirection|.
Note: You can control size of fzf window by using |g:trans_win_height|. It is
not possible to change position of fzf window due to some difficulties with
asynchronous running fzf process in terminal buffer. See this issue for more
details: `https://github.com/junegunn/fzf/issues/1577`
------------------------------------------------------------------------------
KEY MAPPING *trans-keys*
The following mappings are valid in the translate window:
<CR>/<Enter> Add translation under cursor to history file.
q Close the translation/history window.
By default plugin doesn't provide any global mapped keys. But you can create
your own key mapping for fast translation.
Example of key mapping: >
inoremap <silent> <leader>t <ESC>:Trans<CR>
nnoremap <silent> <leader>t :Trans<CR>
vnoremap <silent> <leader>t :Trans<CR>
nnoremap <silent> <leader>td :TransSelectDirection<CR>
vnoremap <silent> <leader>td :TransSelectDirection<CR>
You can map all other commands in this way.
------------------------------------------------------------------------------
IMPORT HISTORY TO ANKI *trans-Anki*
Full instruction you can find on wiki:
https://github.com/echuraev/translate-shell.vim/wiki/Create-and-import-Anki-cards
You can import your history file to Anki.
1. You can configure format of your history file to one of format that
supports by Anki by setting |g:trans_history_format|, for example csv format:
>
let g:trans_history_format = '%s;%t;%as;%at'
<
2. Create type of cards that supports your fields.
3. Import your history file and copy all '*.mp3' files from directory with
history file to Anki media directory:
>
cp -f <path_to_dir_with_history_file>/*.mp3 <path_to_anki_media_dir>
<
By default Anki media directory is:
>
~/Documents/Anki/<UserName>/collection.media/
<
4. Learn your cards with Anki :)
==============================================================================
CONFIGURATION *trans-configuration*
*g:trans_bin*
g:trans_bin~
Default: empty
Use this option to specify the location of your translate-shell executable.
Only needed if it is not in one of the directories in your $PATH environment
variable.
Example:
>
let g:trans_bin = "~/.vim"
<
*g:trans_default_direction*
g:trans_default_direction~
Default: empty
Use this option to specify default direction of translate. If variable is
empty then the source text translates into the language of your `locale`.
Example:
>
let g:trans_default_direction = ":ru"
<
or to specify two target languages:
>
let g:trans_default_direction = ":ru+de"
<
Note: Codes of languages you can find here:
https://github.com/soimort/translate-shell#code-list
Or run the following command in terminal: `trans -R`
*g:trans_directions_list*
g:trans_directions_list~
Default: empty list
Use this option to specify the list of your translate directions. This list is
used in the following commands:
|:TransSelectDirection|, |:TransInteractive|.
This list contains lists of direction. First member of the list is source text
language, second and other are the target translation languages. If member is
empty (`''`) then language will be automatically determined.
Example:
>
let g:trans_directions_list = [
\['en', 'ru'],
\['ru', 'en'],
\['en', 'de'],
\['en', 'ru', 'de'],
\['', 'ru'],
\['', ''],
\]
<
For this list you get the following choose:
>
Select languages:
1. [English -> Russian]
2. [Russian -> English]
3. [English -> German]
4. [English -> Russian, German]
5. [Autodetect -> Russian]
6. [Autodetect -> Autodetect]
<
Note: Codes of languages you can find here:
https://github.com/soimort/translate-shell#code-list
*g:trans_interactive_full_list*
g:trans_interactive_full_list~
Default: 0
By default |:TransInteractive| takes variants for translation from predefined
list |g:trans_directions_list|. If you wish to select translation direction
from all possible variants, you should use this variable.
Example:
>
let g:trans_interactive_full_list = 1
<
*g:trans_advanced_options*
g:trans_advanced_options~
Default: empty
Use this option to specify additional options for translate-shell.
Example:
>
let g:trans_advanced_options = "-brief"
<
*g:trans_win_width*
g:trans_win_width~
Default: 50
Width of the translate windows in characters.
Example:
>
let g:trans_win_width = 40
<
*g:trans_win_height*
g:trans_win_height~
Default: 15
Height of the translate windows in characters.
Example:
>
let g:trans_win_height = 30
<
*g:trans_win_position*
g:trans_win_position~
Default: 'bottom'
This variable determines position of translate window.
Possible values are:
'bottom': Windows is in the bottom of the screen.
'up': Windows is in the up of the screen.
'left': Windows is in the left side of the screen.
'right': Windows is in the right side of the screen.
Example:
>
let g:trans_win_position = "right"
<
*g:trans_join_lines*
g:trans_join_lines~
Default: 0
This option is important only for visual selection. By default the
translate-shell.vim will not join lines but sometimes it could add some
inaccuracies in translation especially when automatic text wrapping is
enabled. It's happen because google translate thinks that every new line is
the new sentence.
If |g:trans_join_lines| is used then lines for translate will join to one. And
it can improve the quality of translation.
Example:
>
let g:trans_join_lines = 1
<
*g:trans_save_raw_history*
g:trans_save_raw_history~
Default: 0
Use this option to enable saving history. This variable should be set in pair
with |g:trans_history_raw_file|. 'raw history' means that it will save all
history of using plugin and will save only words (without translation) that
were translated.
Example:
>
let g:trans_save_raw_history = 1
<
*g:trans_history_raw_file*
g:trans_history_raw_file
Default: '~/.vim/.trans_raw_history'
Use this option to specify the location of your raw history file. Only needed
if variable |g:trans_save_raw_history| was set.
Example:
>
let g:trans_history_raw_file = '~/.trans_raw_history'
<
*g:trans_save_history*
g:trans_save_history~
Default: 0
Use this option to enable saving history. This variable should be set in pair
with |g:trans_history_file|. Use this variable to save history of translation
with selected translation. If this variable is specified then you can press
<Enter> in translate window to select translation to saving. Format of saved
file you can specify with |g:trans_history_format|.
Possible values are:
0: Saving history is disabled.
1: Save all translations to one file that specified in
|g:trans_history_file|.
2: Save all translations in separate files. Files are separated by the
source language. To the name of file that specified in
|g:trans_history_file| will be added postfix with code of source
language.
Example:
- We specified |g:trans_history_file| in the following way:
>
let g:trans_history_file = '~/trans_history/trans_history.csv'
<
- All translations from English will be saved in the following file:
>
~/trans_history/trans_history_en.csv
<
- All translations from German will be saved in the following file:
>
~/trans_history/trans_history_de.csv
<
3: Save all translations in separate files. Files are separated by the
source language and target language. To the name of file that specified
in |g:trans_history_file| will be added postfix with code of source
language and code of target language.
Example:
- We specified |g:trans_history_file| in the following way:
>
let g:trans_history_file = '~/trans_history/trans_history.csv'
<
- All translations from English to Russian will be saved in the
following file:
>
~/trans_history/trans_history_en_ru.csv
<
- All translations from English to German will be saved in the
following file:
>
~/trans_history/trans_history_en_de.csv
<
Example:
>
let g:trans_save_history = 1
<
*g:trans_history_file*
g:trans_history_file
Default: ''
Use this option to specify the location of your translate history file. Only
needed if variable |g:trans_save_history| was set. If directory where history
file should be saved doesn't exist, when try to create the directory.
Example:
>
let g:trans_history_file = '~/trans_history/trans_history.csv'
<
*g:trans_history_format*
g:trans_history_format
Default: '%s;%t'
Use this option to specify the format of translate history file. Only needed
if variable |g:trans_save_history| was set. Use flags to specify format. You
can import this file to Anki (see |trans-Anki|).
Possible flags are:
'%s': on place of this flag will be putted source word.
'%t': on place of this flag will be putted target word.
'%as': on place of this flag will be putted string with audio file for
source word. You should use this flag with option
|g:trans_save_audio|.
'%at': on place of this flag will be putted string with audio file for
target word. You should use this flag with option
|g:trans_save_audio|.
Example:
>
let g:trans_history_format = '%s;%t;%as;%at'
<
*g:trans_close_window_after_saving*
g:trans_close_window_after_saving~
Default: 0
Use this option to specify that translate window should be closed after
selecting translation to save.
Example:
>
let g:trans_close_window_after_saving = 1
<
*g:trans_save_only_unique*
g:trans_save_only_unique~
Default: 0
Use this option to specify that only new words should be added to
|g:trans_history_file|.
Possible values are:
0: Doesn't check is word unique or not.
1: If word is already in |g:trans_history_file| will print message about it.
2: If word is already in |g:trans_history_file| will add new translation
to this word.
Example:
>
let g:trans_save_only_unique = 2
<
*g:trans_save_audio*
g:trans_save_audio~
Default: 0
Use this option to specify that you'd like to download audio files for
translation. The audio will be downloaded in the same directory where
|g:trans_history_file| is located. After that you could import this history
and audio to Anki. See |trans-Anki| for more details.
Example:
>
let g:trans_save_audio = 1
<
*g:trans_ignore_audio_for_langs*
g:trans_ignore_audio_for_langs~
Default: empty list
Use this option to specify the list of languages for which you don't want to
download audio files.
Example:
>
let g:trans_ignore_audio_for_langs = ['ru', 'de']
<
In this case audio files for Russian and German languages won't download.
==============================================================================
CHANGELOG *trans-changelog*
2.1.0 (2019-05-15)
- Added function for changing default translate direction for a session
- Implemented FZF functions for the following functions:
* TransSelectDirection -> FZFTransSelectDirection
* TransInteractive -> FZFTransInteractive
* TransChangeDefaultDirection -> FZFTransChangeDefaultDirection
- Refactored code
- Added new tests
- Added g:trans_interactive_full_list variable
2.0.1 (2018-11-09)
- Added search of translate direction in passed args
- Enhanced function for line joining
2.0 (2018-11-03)
- Unified :Trans and :TransVisual functions
1.2 (2018-10-25)
- Pressing |q| in translate buffer will close translate window
- Do not open buffer is result is empty and option -no-translate was
passed
1.1.1 (2018-10-08)
- Notifications about audio downloading are only for words that will be
downloaded.
- Fix issue with adding words to history file if buffer is open.
- Fix issue with adding words to history file if file is open and on the
screen.
- Fix issue with saving same words: niemanden and niemand.
1.1 (2018-05-29)
- Keep translate story. Choose the better translate to save.
- Download audio for translation.
- Import translation history to Anki.
1.0 (2018-05-15)
- Initial release
==============================================================================
TODO *trans-todo*
- Nice syntax highlighting
- Folding for translation on multiple languages
- Async downloading audio for vim 8 (may be for all system calls)
- Limit on the size of history files
==============================================================================
vim: tw=78 ts=8 sw=4 sts=4 et ft=help