jekyll-chatgpt-translate 0.0.43 → 0.0.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +22 -0
- data/.github/workflows/markdown-lint.yml +40 -0
- data/.github/workflows/rake.yml +21 -0
- data/.github/workflows/yamllint.yml +36 -0
- data/.rubocop.yml +23 -1
- data/.rultor.yml +23 -1
- data/Gemfile +6 -6
- data/README.md +93 -55
- data/features/cli.feature +35 -0
- data/features/step_definitions/steps.rb +4 -0
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +16 -11
- data/lib/jekyll-chatgpt-translate/generator.rb +6 -0
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/logo.png +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac33cf289fbc970376efe2e1b6af0693db8a2c8875d059dec1d228c89baee96b
|
4
|
+
data.tar.gz: 3baa2cb4e88e93f3fe26cfb253b7ca939269d351930ba56f10c10aa6f5766c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 629df2b5bbdaf7f51a562d5e941c93e9a18d07dbd868694010076c8657896e7827123b71478d60d903b645dc722e81bd274478de80b68b87bbfe78316cea69ea
|
7
|
+
data.tar.gz: a8099c472aeb3e73f71b94a8221f2bbd549571f1d9414e8b9d787b66823f3d1db9b5411a1a7047376684925c457110e62b1578af463857c3b95d7ab02271ec2d
|
data/.0pdd.yml
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
errors:
|
2
24
|
- yegor256@gmail.com
|
3
25
|
# alerts:
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included
|
13
|
+
# in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
23
|
+
name: markdown-lint
|
24
|
+
'on':
|
25
|
+
push:
|
26
|
+
branches:
|
27
|
+
- master
|
28
|
+
pull_request:
|
29
|
+
branches:
|
30
|
+
- master
|
31
|
+
paths-ignore: ['paper/**', 'sandbox/**']
|
32
|
+
concurrency:
|
33
|
+
group: markdown-lint-${{ github.ref }}
|
34
|
+
cancel-in-progress: true
|
35
|
+
jobs:
|
36
|
+
markdown-lint:
|
37
|
+
runs-on: ubuntu-22.04
|
38
|
+
steps:
|
39
|
+
- uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
|
40
|
+
- uses: articulate/actions-markdownlint@v1
|
data/.github/workflows/rake.yml
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
1
22
|
---
|
2
23
|
name: rake
|
3
24
|
on:
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included
|
13
|
+
# in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
23
|
+
name: yamllint
|
24
|
+
'on':
|
25
|
+
push:
|
26
|
+
branches:
|
27
|
+
- master
|
28
|
+
pull_request:
|
29
|
+
branches:
|
30
|
+
- master
|
31
|
+
jobs:
|
32
|
+
yamllint:
|
33
|
+
runs-on: ubuntu-22.04
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v4
|
36
|
+
- uses: ibiqlik/action-yamllint@v3
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
AllCops:
|
2
24
|
Exclude:
|
3
25
|
- 'bin/**/*'
|
@@ -20,7 +42,7 @@ Metrics/AbcSize:
|
|
20
42
|
Metrics/BlockLength:
|
21
43
|
Max: 100
|
22
44
|
Metrics/CyclomaticComplexity:
|
23
|
-
Max:
|
45
|
+
Max: 35
|
24
46
|
Metrics/PerceivedComplexity:
|
25
47
|
Max: 40
|
26
48
|
Layout/EmptyLineAfterGuardClause:
|
data/.rultor.yml
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
docker:
|
2
|
-
image: yegor256/rultor-image:1.
|
24
|
+
image: yegor256/rultor-image:1.23.1
|
3
25
|
assets:
|
4
26
|
rubygems.yml: yegor256/home#assets/rubygems.yml
|
5
27
|
install: |
|
data/Gemfile
CHANGED
@@ -25,11 +25,11 @@
|
|
25
25
|
source 'https://rubygems.org'
|
26
26
|
gemspec
|
27
27
|
|
28
|
-
gem 'cucumber', '9.
|
28
|
+
gem 'cucumber', '9.2.0', require: false
|
29
29
|
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
30
|
-
gem 'minitest', '5.
|
31
|
-
gem 'rake', '13.1
|
32
|
-
gem 'rubocop', '1.
|
33
|
-
gem 'rubocop-rspec', '2.
|
30
|
+
gem 'minitest', '5.22.3', require: false
|
31
|
+
gem 'rake', '13.2.1', require: false
|
32
|
+
gem 'rubocop', '1.63.2', require: false
|
33
|
+
gem 'rubocop-rspec', '2.29.1', require: false
|
34
34
|
gem 'simplecov', '0.22.0', require: false
|
35
|
-
gem 'webmock', '3.
|
35
|
+
gem 'webmock', '3.23.0', require: false
|
data/README.md
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
|
1
|
+
# Translator of Jekyll Pages via ChatGPT
|
2
|
+
|
3
|
+
![logo](logo.png)
|
2
4
|
|
3
5
|
[![rake](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml)
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/jekyll-chatgpt-translate.svg)](http://badge.fury.io/rb/jekyll-chatgpt-translate)
|
5
7
|
|
6
|
-
If you have a [Jekyll](https://jekyllrb.com/) static site,
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
If you have a [Jekyll](https://jekyllrb.com/) static site,
|
9
|
+
this plugin may help you automatically
|
10
|
+
translate its pages to another language, through
|
11
|
+
[ChatGPT](https://chat.openai.com/). See how it
|
12
|
+
works for [my blog](https://github.com/yegor256/ru.yegor256.com),
|
13
|
+
for example [this page](https://ru.yegor256.com/2023-08-13-dictators.html)
|
14
|
+
is translated to
|
10
15
|
[English](https://ru.yegor256.com/english/2023-08-13-dictators.html).
|
11
16
|
|
12
|
-
Install it first (you need
|
17
|
+
Install it first (you need
|
18
|
+
[Ruby 3+](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/)
|
13
19
|
and [Jekyll 3+](https://jekyllrb.com/)):
|
14
20
|
|
15
|
-
```
|
21
|
+
```bash
|
16
22
|
gem install jekyll-chatgpt-translate
|
17
23
|
```
|
18
24
|
|
@@ -32,92 +38,124 @@ chatgpt-translate:
|
|
32
38
|
permalink: :year-:month-:day-:slug-chinese.html
|
33
39
|
layout: chinese-translated
|
34
40
|
-
|
41
|
+
only: ru-post
|
35
42
|
language: fr
|
36
43
|
permalink: :year-:month-:day-:title-french.html
|
37
44
|
```
|
38
45
|
|
39
|
-
Here, the source language is English (`en`), the targets are
|
46
|
+
Here, the source language is English (`en`), the targets are
|
47
|
+
Chinese (`zh`) and French (`fr`),
|
40
48
|
where the layout for Chinese is `_layout/chinese-translated.html` and for
|
41
49
|
French is `_layout/translated.html` (you must have these files).
|
42
50
|
|
43
|
-
OpenAI API KEY must be set in the `OPENAI_API_KEY` environment variable,
|
44
|
-
|
45
|
-
|
51
|
+
OpenAI API KEY must be set in the `OPENAI_API_KEY` environment variable,
|
52
|
+
otherwise
|
53
|
+
the plugin will not do any translation and won't generate translated pages.
|
54
|
+
You can get your key
|
55
|
+
[here][open-ai].
|
46
56
|
|
47
|
-
OpenAI API
|
57
|
+
OpenAI API base URL can be customized by the `OPENAI_API_BASE`
|
58
|
+
environment variable.
|
59
|
+
If this variable is not set, the default value is `https://api.openai.com/`.
|
48
60
|
|
49
|
-
Inside the original page you can use `{{ page.chatgpt-translate.urls[XX] }}`
|
50
|
-
|
61
|
+
Inside the original page you can use `{{ page.chatgpt-translate.urls[XX] }}`
|
62
|
+
in order to render the URL
|
63
|
+
of the translated page, where `XX` is the [ISO-639-1][iso-639]
|
51
64
|
code of the target language.
|
52
|
-
Inside the translated page you can use
|
53
|
-
|
65
|
+
Inside the translated page you can use
|
66
|
+
`{{ page.chatgpt-translate.original-url }}` in order
|
67
|
+
to get the URL of the page that was translated.
|
54
68
|
|
55
69
|
You can also use `{{ page.chatgpt-translate.model }}`
|
56
|
-
inside both the original page and the translated one,
|
70
|
+
inside both the original page and the translated one,
|
71
|
+
to refer to the model of ChatGPT.
|
57
72
|
The presence of `{{ page.chatgpt-translate }}` means that the
|
58
|
-
page was translated or the translated HTML was downloaded
|
73
|
+
page was translated or the translated HTML was downloaded
|
74
|
+
and placed into the `_site` directory.
|
59
75
|
|
60
76
|
## Options
|
61
77
|
|
62
78
|
Full list of options available to specify in `_config.yml`:
|
63
79
|
|
64
|
-
|
65
|
-
|
80
|
+
* `api_key_file` (optional) — the file with OpenAI API key.
|
81
|
+
If this option is not specified,
|
82
|
+
it is expected to have the key in the `OPENAI_API_KEY` environment variable.
|
66
83
|
|
67
|
-
|
68
|
-
|
84
|
+
* `api_key` (optional) — the OpenAI API key itself. This is a very bad idea to
|
85
|
+
specify it right in the `_config.yml` file, but it's still possible.
|
69
86
|
|
70
|
-
|
71
|
-
|
87
|
+
* `model` (optional) — specifies the model to use by ChatGPT,
|
88
|
+
[examples are here](https://github.com/alexrudall/ruby-openai#models).
|
72
89
|
|
73
|
-
|
74
|
-
code of the source language.
|
90
|
+
* `source` (optional) — is the [ISO-639-1][iso-639] code of the source language.
|
75
91
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
92
|
+
* `no_download` (optional) — if this attribute is present, the plugin won't try
|
93
|
+
to find HTML versions of translated pages in the Internet and won't try to
|
94
|
+
download them and place into the `_site` directory. Thus, your entire site
|
95
|
+
will have to be re-translated on every build (might be very ineffective
|
96
|
+
if the site is big!)
|
80
97
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
98
|
+
* `min_chars` (optional) — minimum number of chars that must be present in
|
99
|
+
a paragraph in order for it to be feasible to go to ChatGPT. The robot
|
100
|
+
doesn't translate short paragraphs pretty enough. It's better to keep this
|
101
|
+
number big enough, to avoid silly translations. The default is 128.
|
85
102
|
|
86
|
-
|
87
|
-
|
103
|
+
* `window_length` (optional) — maximum number of words to be sent to
|
104
|
+
OpenAI API in one
|
105
|
+
request. The default is 2048.
|
88
106
|
|
89
|
-
|
90
|
-
|
91
|
-
|
107
|
+
* `layout` (optional) — is name of the file in `_layouts` directory,
|
108
|
+
without the extension.
|
109
|
+
This layout will be specified for the pages generated by this plugin.
|
110
|
+
The default value is `translated` (expecting you to have
|
111
|
+
`_layouts/translated.html` file available).
|
92
112
|
|
93
|
-
|
113
|
+
* `targets` (mandatory) — an array of target languages, each of
|
114
|
+
which has the following attributes
|
94
115
|
|
95
|
-
|
116
|
+
* `only` (optional) —
|
117
|
+
it this is present, only the posts with the provided "layout"
|
118
|
+
will be translated to this target
|
96
119
|
|
97
|
-
|
120
|
+
* `language` (mandatory) —
|
121
|
+
[ISO-639-1][iso-639] code of the target language
|
98
122
|
|
99
|
-
|
123
|
+
* `permalink` (mandatory) — template to use for newly generated pages
|
100
124
|
|
101
|
-
* `
|
102
|
-
The default value is 1024. It is recommended to use smaller number, in order
|
103
|
-
to avoid too long builds. You can re-run the build again and missing pages
|
104
|
-
will be generated. Thus, in a few builds the entire site will be translated.
|
125
|
+
* `layout` (optional) — the name of the file in the `_layouts` directory
|
105
126
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
127
|
+
* `threshold` (optional) — maximum number of pages to generate
|
128
|
+
in one build cycle.
|
129
|
+
The default value is 1024. It is recommended to use smaller number, in order
|
130
|
+
to avoid too long builds. You can re-run the build again and missing pages
|
131
|
+
will be generated. Thus, in a few builds the entire site will be translated.
|
110
132
|
|
111
|
-
|
112
|
-
|
133
|
+
* `version` (optional) — the version that will be attached to each
|
134
|
+
generated page,
|
135
|
+
in order to avoid repetitive translations on one hand
|
136
|
+
and enable re-translations
|
137
|
+
when the `version` is changed on another hand. By default, the version of
|
138
|
+
this plugin will be used, unless you set your own value.
|
139
|
+
|
140
|
+
* `tmpdir` (optional) — the name of the directory where to keep temporary files,
|
141
|
+
`_chatgpt-translate` is the default value.
|
113
142
|
|
114
143
|
## How to Contribute
|
115
144
|
|
116
145
|
Make a fork and then test it locally like this:
|
117
146
|
|
118
147
|
```bash
|
119
|
-
|
120
|
-
|
148
|
+
bundle update
|
149
|
+
bundle exec rake
|
121
150
|
```
|
122
151
|
|
123
152
|
If it works, make changes, test again, and then submit a pull request.
|
153
|
+
|
154
|
+
In order to run a single test, do this:
|
155
|
+
|
156
|
+
```bash
|
157
|
+
bundle exec ruby test/test_generator.rb
|
158
|
+
```
|
159
|
+
|
160
|
+
[open-ai]: https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key
|
161
|
+
[iso-639]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
data/features/cli.feature
CHANGED
@@ -207,3 +207,38 @@ Feature: Simple site building
|
|
207
207
|
And Stdout contains "The page is absent, need to translate"
|
208
208
|
And File "_site/2023/01/01/hello.html" exists
|
209
209
|
And File "_site/2023/01/01/hello.html" contains "NO TRANSLATION!"
|
210
|
+
|
211
|
+
Scenario: Translation skipped due to the ONLY tag
|
212
|
+
Given I have a "_config.yml" file with content:
|
213
|
+
"""
|
214
|
+
url: https://www.yegor256.com
|
215
|
+
markdown: kramdown
|
216
|
+
plugins:
|
217
|
+
- jekyll-chatgpt-translate
|
218
|
+
chatgpt-translate:
|
219
|
+
source: en
|
220
|
+
threshold: 0
|
221
|
+
api_key: "it-is-not-used, because EN to EN translation"
|
222
|
+
layout: default
|
223
|
+
targets:
|
224
|
+
-
|
225
|
+
only: ABC
|
226
|
+
language: en
|
227
|
+
permalink: :slug-en.html
|
228
|
+
"""
|
229
|
+
And I have a "_layouts/default.html" file with content:
|
230
|
+
"""
|
231
|
+
{{ content }}
|
232
|
+
"""
|
233
|
+
And I have a "_posts/2023-01-01-hello.md" file with content:
|
234
|
+
"""
|
235
|
+
---
|
236
|
+
layout: default
|
237
|
+
title: foo
|
238
|
+
---
|
239
|
+
Hello, world!
|
240
|
+
"""
|
241
|
+
Then I build Jekyll site
|
242
|
+
And Exit code is zero
|
243
|
+
And File "_site/2023/01/01/hello.html" exists
|
244
|
+
And File "_site/2023/01/01/hello-en.html" doesn't exist
|
@@ -53,6 +53,10 @@ Then('File {string} exists') do |string|
|
|
53
53
|
raise "The file \"#{string}\" is absent:\n#{`tree -s`}" unless File.exist?(string)
|
54
54
|
end
|
55
55
|
|
56
|
+
Then('File {string} doesn\'t exist') do |string|
|
57
|
+
raise "The file \"#{string}\" is present:\n#{`tree -s`}" if File.exist?(string)
|
58
|
+
end
|
59
|
+
|
56
60
|
Then('File {string} contains {string}') do |string, string2|
|
57
61
|
raise "The file \"#{string}\" is absent" unless File.exist?(string)
|
58
62
|
content = File.read(string)
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
29
29
|
s.required_ruby_version = '>= 3.0'
|
30
30
|
s.name = 'jekyll-chatgpt-translate'
|
31
|
-
s.version = '0.0.
|
31
|
+
s.version = '0.0.44'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -57,12 +57,13 @@ class GptTranslate::ChatGPT
|
|
57
57
|
def api_base_url
|
58
58
|
url = ENV.fetch('OPENAI_API_BASE', 'https://api.openai.com/')
|
59
59
|
Jekyll.logger.info("Current OpenAI API Base URL: #{url.inspect}")
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
unless url == 'https://api.openai.com/'
|
61
|
+
Jekyll.logger.warn(
|
62
|
+
'Warning: You\'re using a custom endpoint for the OpenAI API. ' \
|
63
|
+
'The provider of this endpoint may have access to all details ' \
|
64
|
+
'of your requests. Only use a custom endpoint if you trust the provider.'
|
65
|
+
)
|
66
|
+
end
|
66
67
|
url
|
67
68
|
end
|
68
69
|
|
@@ -154,15 +155,19 @@ class GptTranslate::ChatGPT
|
|
154
155
|
rescue StandardError => e
|
155
156
|
attempt += 1
|
156
157
|
if attempt < 4
|
157
|
-
Jekyll.logger.error(
|
158
|
-
|
158
|
+
Jekyll.logger.error(
|
159
|
+
"ChatGPT failed to answer to #{prompt.inspect}" \
|
160
|
+
"(attempt no.#{attempt}): #{e.message.inspect}"
|
161
|
+
)
|
159
162
|
retry
|
160
163
|
end
|
161
164
|
raise e
|
162
165
|
end
|
163
|
-
Jekyll.logger.info(
|
164
|
-
|
165
|
-
|
166
|
+
Jekyll.logger.info(
|
167
|
+
"Translated #{par.split.count} #{@source.upcase} words " \
|
168
|
+
"to #{answer.split.count} #{@target.upcase} words " \
|
169
|
+
"through #{@model} in #{(Time.now - start).round(2)}s: #{"#{par[0..24]}...".inspect}"
|
170
|
+
)
|
166
171
|
answer
|
167
172
|
end
|
168
173
|
end
|
@@ -63,11 +63,17 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
63
63
|
marker = "Translated by ChatGPT #{model}#{version.empty? ? '' : "/#{version}"}"
|
64
64
|
site.posts.docs.shuffle.each_with_index do |doc, pos|
|
65
65
|
plain = GptTranslate::Plain.new(doc.content).to_s
|
66
|
+
layout = doc['layout']
|
66
67
|
config['targets'].each do |target|
|
67
68
|
pstart = Time.now
|
68
69
|
link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
|
69
70
|
lang = target['language']
|
70
71
|
raise 'Language must be defined for each target' if target.nil?
|
72
|
+
only = target['only']
|
73
|
+
if !only.nil? && layout != only
|
74
|
+
Jekyll.logger.debug("Not translating #{link.inspect}, b/c 'only' set to '#{only}'")
|
75
|
+
next
|
76
|
+
end
|
71
77
|
path = File.join(home, lang, doc.basename.gsub(/\.md$/, "-#{lang}.md"))
|
72
78
|
FileUtils.mkdir_p(File.dirname(path))
|
73
79
|
File.write(
|
data/logo.png
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-chatgpt-translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.44
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: humanize
|
@@ -132,7 +132,9 @@ extra_rdoc_files:
|
|
132
132
|
- LICENSE.txt
|
133
133
|
files:
|
134
134
|
- ".0pdd.yml"
|
135
|
+
- ".github/workflows/markdown-lint.yml"
|
135
136
|
- ".github/workflows/rake.yml"
|
137
|
+
- ".github/workflows/yamllint.yml"
|
136
138
|
- ".gitignore"
|
137
139
|
- ".pdd"
|
138
140
|
- ".rubocop.yml"
|