Skip to content

Commit

Permalink
Merge pull request #2 from gw31415/feature/doc
Browse files Browse the repository at this point in the history
fix #1
  • Loading branch information
gw31415 committed Sep 8, 2022
2 parents 823c51f + f4e6e77 commit 852a6c7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# DeepL.vim

Provides functions to wrap the DeepL API.

## Installation

### 1. Installation of this plugin

[Plug.vim](https://github.com/junegunn/vim-plug)
```vim
Plug 'gw31415/deepl.vim'
```

[dein.vim](https://github.com/Shougo/dein.vim)
```vim
call dein#add('gw31415/deepl.vim')
```

[packer.nvim](https://github.com/wbthomason/packer.nvim)
```lua
use 'gw31415/deepl.vim'
```

### 2. Configuration of Auth Key

```vim
let g:deepl_auth_key = '{Your auth key of DeepL API}'
```

## Example
Create a command `:{range}DeepL` that translates the selected lines and adds the translation just below the selection.
If the command called with a exclamation mark(`:{range}DeepL!`), the lines will be replaced with the translation.

```vim
fu! s:deepl(l1, l2, bang) abort
let in = join(getline(a:l1, a:l2), "\n")
let out = split(deepl#translate(in, 'EN'), "\n")
if a:bang == ''
cal append(a:l2, out)
el
cal setline(a:l1, out)
en
endfu
com! -range -bang DeepL cal s:deepl(<line1>, <line2>, '<bang>')
```
44 changes: 44 additions & 0 deletions doc/deepl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
*DeepL.vim* *deepl.vim*
Author: Amadeus_vn<git@amas.dev>
License: zlib License

|DeepL.vim| provides functions to wrap the DeepL API.

============================================================================
Functions

deepl#translate({text}, {target_lang}) *deepl#transllate()*

Translates {text} to {target_lang} and returns the translation result.


============================================================================
Variables

*g:deepl_auth_key* Your Auth Key to access DeepL API.
(Initially, this variable is not declared.)

*g:deepl_endpoint* The Endpoint URL of DeepL API.
(Default: 'https://api-free.deepl.com/v2/translate')

============================================================================
Example

In the example below, the command `:{range}DeepL` is created that translates
the selected lines and adds the translation just below the selection. If the
command called with a exclamation mark ( `:{range}DeepL!` ), the lines will be
replaced with the translation.
>
fu! s:deepl(l1, l2, bang) abort
let in = join(getline(a:l1, a:l2), "\n")
let out = split(deepl#translate(in, 'EN'), "\n")
if a:bang == ''
cal append(a:l2, out)
el
cal setline(a:l1, out)
en
endfu
com! -range -bang DeepL cal s:deepl(<line1>, <line2>, '<bang>')
<

vim:tw=78:ts=8:noet:ft=help:norl:

0 comments on commit 852a6c7

Please sign in to comment.