jekyll-chatgpt-translate 0.0.1
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.
- checksums.yaml +7 -0
- data/.0pdd.yml +9 -0
- data/.github/workflows/rake.yml +24 -0
- data/.gitignore +5 -0
- data/.pdd +7 -0
- data/.rubocop.yml +29 -0
- data/.rultor.yml +22 -0
- data/Gemfile +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +80 -0
- data/features/cli.feature +42 -0
- data/features/gem_package.feature +24 -0
- data/features/step_definitions/steps.rb +88 -0
- data/features/support/env.rb +23 -0
- data/jekyll-chatgpt-translate.gemspec +50 -0
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +113 -0
- data/lib/jekyll-chatgpt-translate/generator.rb +100 -0
- data/lib/jekyll-chatgpt-translate/plain.rb +84 -0
- data/lib/jekyll-chatgpt-translate/version.rb +27 -0
- data/lib/jekyll-chatgpt-translate.rb +25 -0
- data/renovate.json +10 -0
- data/test/test__helper.rb +26 -0
- data/test/test_chatgpt.rb +47 -0
- data/test/test_generator.rb +36 -0
- data/test/test_plain.rb +56 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 903d9dcdc683aff4816e02d7e49b699d3b8393a64716b162c5b46509efa77a7a
|
4
|
+
data.tar.gz: a202b7a057a6294046ba081ab8432ee6ef2a3c398a93805bf95b87c8fde76731
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e5ae442015d83a9b7f9a5408826dc1c0ed808abb1bf3b9b7339f87d40d7ba6b0e6518547d9bc707a00b7a98c30bc1d2e3fcf41ed576b175e215f764ed8dcf7d
|
7
|
+
data.tar.gz: 19e9825b50ecd0b72bf9acde8f330d47f1a00964516570e967d3dbe0e3d1077069dddcb6daac7eb1851bd8fcc2d52be0044a060320c83621fff3dac5a36a9da0
|
data/.0pdd.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
name: rake
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
name: test
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
os: [ubuntu-20.04, macos-12, windows-2022]
|
16
|
+
ruby: [2.7, 3.1]
|
17
|
+
runs-on: ${{ matrix.os }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- run: bundle update
|
24
|
+
- run: bundle exec rake
|
data/.gitignore
ADDED
data/.pdd
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'bin/**/*'
|
4
|
+
- 'assets/**/*'
|
5
|
+
DisplayCopNames: true
|
6
|
+
TargetRubyVersion: 2.3
|
7
|
+
SuggestExtensions: false
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
Gemspec/RequiredRubyVersion:
|
11
|
+
Enabled: false
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Enabled: false
|
14
|
+
Style/ClassAndModuleChildren:
|
15
|
+
Enabled: false
|
16
|
+
Layout/MultilineMethodCallIndentation:
|
17
|
+
Enabled: false
|
18
|
+
Metrics/AbcSize:
|
19
|
+
Enabled: false
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Max: 30
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Max: 10
|
24
|
+
Metrics/PerceivedComplexity:
|
25
|
+
Max: 10
|
26
|
+
Layout/EmptyLineAfterGuardClause:
|
27
|
+
Enabled: false
|
28
|
+
Naming/FileName:
|
29
|
+
Enabled: false
|
data/.rultor.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
docker:
|
2
|
+
image: yegor256/rultor-image:1.21.0
|
3
|
+
assets:
|
4
|
+
rubygems.yml: yegor256/home#assets/rubygems.yml
|
5
|
+
install: |
|
6
|
+
pdd -f /dev/null
|
7
|
+
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
8
|
+
release:
|
9
|
+
script: |-
|
10
|
+
bundle exec rake
|
11
|
+
rm -rf *.gem
|
12
|
+
sed -i "s/0\.0\.0/${tag}/g" jekyll-chatgpt-translate.gemspec
|
13
|
+
sed -i "s/0\.0\.0/${tag}/g" lib/jekyll-chatgpt-translate/version.rb
|
14
|
+
git add jekyll-chatgpt-translate.gemspec
|
15
|
+
git add lib/jekyll-chatgpt-translate/version.rb
|
16
|
+
git commit -m "version set to ${tag}"
|
17
|
+
gem build jekyll-chatgpt-translate.gemspec
|
18
|
+
chmod 0600 ../rubygems.yml
|
19
|
+
gem push *.gem --config-file ../rubygems.yml
|
20
|
+
merge:
|
21
|
+
script: |-
|
22
|
+
bundle exec rake
|
data/Gemfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
source 'https://rubygems.org'
|
26
|
+
gemspec
|
27
|
+
|
28
|
+
gem 'cucumber', '8.0.0', require: false
|
29
|
+
gem 'jekyll', '3.9.2', require: false
|
30
|
+
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
31
|
+
gem 'minitest', '5.19.0', require: false
|
32
|
+
gem 'rake', '13.0.6', require: false
|
33
|
+
gem 'rubocop', '1.55.1', require: false
|
34
|
+
gem 'rubocop-rspec', '2.23.2', require: false
|
35
|
+
gem 'simplecov', '0.22.0', require: false
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2023 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.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml)
|
2
|
+
[](http://badge.fury.io/rb/jekyll-chatgpt-translate)
|
3
|
+
|
4
|
+
Install it first:
|
5
|
+
|
6
|
+
```
|
7
|
+
gem install jekyll-chatgpt-translate
|
8
|
+
```
|
9
|
+
|
10
|
+
Then, add this to `_config.yml`:
|
11
|
+
|
12
|
+
```yaml
|
13
|
+
chatgpt-translate:
|
14
|
+
source: en
|
15
|
+
layout: translated
|
16
|
+
targets:
|
17
|
+
-
|
18
|
+
language: cn
|
19
|
+
permalink: :year-:month-:day-:title-chinese.html
|
20
|
+
layout: chinese-translated
|
21
|
+
-
|
22
|
+
language: fr
|
23
|
+
permalink: :year-:month-:day-:title-french.html
|
24
|
+
```
|
25
|
+
|
26
|
+
Here, the source language is English (`en`), the target one is Chinese (`cn`),
|
27
|
+
the layout is `_layout/translated.html` (you must have this file).
|
28
|
+
|
29
|
+
OpenAI API KEY must be set in `OPENAI_API_KEY` environment variable, otherwise
|
30
|
+
the plugin will not do any translation and won't generate translated pages.
|
31
|
+
You can get your key [here](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key).
|
32
|
+
|
33
|
+
The plugin is compatible with
|
34
|
+
[Jekyll 3.9.3](https://jekyllrb.com/news/2023/01/29/jekyll-3-9-3-released/) and
|
35
|
+
[Jekyll 4.3.2](https://jekyllrb.com/news/2023/01/20/jekyll-4-3-2-released/).
|
36
|
+
|
37
|
+
# How to Contribute
|
38
|
+
|
39
|
+
Test is like this:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
$ bundle update
|
43
|
+
$ bundle exec rake
|
44
|
+
```
|
45
|
+
|
46
|
+
If it works, make changes, test again, and then submit a pull request.
|
data/Rakefile
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'rake'
|
27
|
+
|
28
|
+
def name
|
29
|
+
@name ||= File.basename(Dir['*.gemspec'].first, '.*')
|
30
|
+
end
|
31
|
+
|
32
|
+
def version
|
33
|
+
Gem::Specification.load(Dir['*.gemspec'].first).version
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rake/clean'
|
37
|
+
task default: %i[clean test features rubocop copyright]
|
38
|
+
|
39
|
+
require 'rake/testtask'
|
40
|
+
desc 'Run all unit tests'
|
41
|
+
Rake::TestTask.new(:test) do |test|
|
42
|
+
Rake::Cleaner.cleanup_files(['coverage'])
|
43
|
+
test.libs << 'lib' << 'test'
|
44
|
+
test.pattern = 'test/**/test_*.rb'
|
45
|
+
test.warning = true
|
46
|
+
test.verbose = false
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'rdoc'
|
50
|
+
require 'rdoc/task'
|
51
|
+
desc 'Build RDoc documentation'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "#{name} #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
58
|
+
|
59
|
+
require 'rubocop/rake_task'
|
60
|
+
desc 'Run RuboCop on all directories'
|
61
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
62
|
+
task.fail_on_error = true
|
63
|
+
task.requires << 'rubocop-rspec'
|
64
|
+
end
|
65
|
+
|
66
|
+
require 'cucumber/rake/task'
|
67
|
+
Cucumber::Rake::Task.new(:features) do
|
68
|
+
Rake::Cleaner.cleanup_files(['coverage'])
|
69
|
+
end
|
70
|
+
Cucumber::Rake::Task.new(:'features:html') do |t|
|
71
|
+
t.profile = 'html_report'
|
72
|
+
end
|
73
|
+
|
74
|
+
task :copyright do
|
75
|
+
sh "grep -q -r '#{Date.today.strftime('%Y')}' \
|
76
|
+
--include '*.rb' \
|
77
|
+
--include '*.txt' \
|
78
|
+
--include 'Rakefile' \
|
79
|
+
."
|
80
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Feature: Simple site building
|
2
|
+
I want to be able to build a site
|
3
|
+
|
4
|
+
Scenario: Simple site
|
5
|
+
Given I have a "_config.yml" file with content:
|
6
|
+
"""
|
7
|
+
markdown: kramdown
|
8
|
+
plugins:
|
9
|
+
- jekyll-chatgpt-translate
|
10
|
+
chatgpt-translate:
|
11
|
+
source: en
|
12
|
+
layout: translated
|
13
|
+
targets:
|
14
|
+
-
|
15
|
+
language: cn
|
16
|
+
permalink: :year-:month-:day-:title-chinese.html
|
17
|
+
layout: chinese-translated
|
18
|
+
-
|
19
|
+
language: fr
|
20
|
+
permalink: :year/:title-french.html
|
21
|
+
"""
|
22
|
+
And I have a "_layouts/default.html" file with content:
|
23
|
+
"""
|
24
|
+
{{ content }}
|
25
|
+
"""
|
26
|
+
And I have a "_layouts/chinese-translated.html" file with content:
|
27
|
+
"""
|
28
|
+
Chinese: {{ content }}
|
29
|
+
"""
|
30
|
+
And I have a "_posts/2023-01-01-hello.md" file with content:
|
31
|
+
"""
|
32
|
+
---
|
33
|
+
layout: default
|
34
|
+
---
|
35
|
+
Hello, world!
|
36
|
+
"""
|
37
|
+
Then I build Jekyll site
|
38
|
+
Then File "_site/2023/01/01/hello.html" exists
|
39
|
+
Then File "_site/2023-01-01-Hello-chinese.html" exists
|
40
|
+
Then File "_site/2023/Hello-french.html" exists
|
41
|
+
And Exit code is zero
|
42
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Gem Package
|
2
|
+
As a source code writer I want to be able to
|
3
|
+
package the Gem into .gem file
|
4
|
+
|
5
|
+
Scenario: Gem can be packaged
|
6
|
+
When it is Unix
|
7
|
+
Given I have a "execs.rb" file with content:
|
8
|
+
"""
|
9
|
+
#!/usr/bin/env ruby
|
10
|
+
require 'rubygems'
|
11
|
+
spec = Gem::Specification::load('./spec.rb')
|
12
|
+
"""
|
13
|
+
And I copy this gem into temp dir
|
14
|
+
When I run bash with:
|
15
|
+
"""
|
16
|
+
set -x
|
17
|
+
set -e
|
18
|
+
cd jekyll-chatgpt-translate
|
19
|
+
gem build jekyll-chatgpt-translate.gemspec
|
20
|
+
gem specification --ruby jekyll-chatgpt-translate-*.gem > ../spec.rb
|
21
|
+
cd ..
|
22
|
+
ruby execs.rb
|
23
|
+
"""
|
24
|
+
Then Exit code is zero
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 NONINFINGEMENT. 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
|
+
require 'tmpdir'
|
24
|
+
require 'English'
|
25
|
+
|
26
|
+
Before do
|
27
|
+
@cwd = Dir.pwd
|
28
|
+
@dir = Dir.mktmpdir('test')
|
29
|
+
FileUtils.mkdir_p(@dir)
|
30
|
+
Dir.chdir(@dir)
|
31
|
+
end
|
32
|
+
|
33
|
+
After do
|
34
|
+
Dir.chdir(@cwd)
|
35
|
+
FileUtils.rm_rf(@dir)
|
36
|
+
end
|
37
|
+
|
38
|
+
Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
|
39
|
+
FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
|
40
|
+
File.write(file, text.gsub('\\xFF', 0xFF.chr))
|
41
|
+
end
|
42
|
+
|
43
|
+
When(/^I build Jekyll site$/) do
|
44
|
+
@stdout = `jekyll build`
|
45
|
+
@exitstatus = $CHILD_STATUS.exitstatus
|
46
|
+
end
|
47
|
+
|
48
|
+
Then(/^Stdout contains "([^"]*)"$/) do |txt|
|
49
|
+
raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
|
50
|
+
end
|
51
|
+
|
52
|
+
Then(/^File "([^"]*)" exists$/) do |name|
|
53
|
+
raise unless File.exist?(name)
|
54
|
+
end
|
55
|
+
|
56
|
+
Then(/^Stdout is empty$/) do
|
57
|
+
raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
|
58
|
+
end
|
59
|
+
|
60
|
+
Then(/^Exit code is zero$/) do
|
61
|
+
raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
|
62
|
+
end
|
63
|
+
|
64
|
+
Then(/^Exit code is not zero$/) do
|
65
|
+
raise 'Zero exit code' if @exitstatus.zero?
|
66
|
+
end
|
67
|
+
|
68
|
+
When(/^I run bash with "([^"]*)"$/) do |text|
|
69
|
+
@stdout = `#{text}`
|
70
|
+
@exitstatus = $CHILD_STATUS.exitstatus
|
71
|
+
end
|
72
|
+
|
73
|
+
When(/^I run bash with:$/) do |text|
|
74
|
+
@stdout = `#{text}`
|
75
|
+
@exitstatus = $CHILD_STATUS.exitstatus
|
76
|
+
end
|
77
|
+
|
78
|
+
When(/^I copy this gem into temp dir$/) do
|
79
|
+
FileUtils.copy_entry(@cwd, File.join(@dir, 'jekyll-chatgpt-translate'))
|
80
|
+
end
|
81
|
+
|
82
|
+
Given(/^It is Unix$/) do
|
83
|
+
pending if Gem.win_platform?
|
84
|
+
end
|
85
|
+
|
86
|
+
Given(/^It is Windows$/) do
|
87
|
+
pending unless Gem.win_platform?
|
88
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 NONINFINGEMENT. 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
|
+
require 'simplecov'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'English'
|
26
|
+
|
27
|
+
Gem::Specification.new do |s|
|
28
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
29
|
+
s.required_ruby_version = '>= 2.6'
|
30
|
+
s.name = 'jekyll-chatgpt-translate'
|
31
|
+
s.version = '0.0.1'
|
32
|
+
s.license = 'MIT'
|
33
|
+
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
|
+
s.description = [
|
35
|
+
'Add this plugin to your Jekyll site and all posts will be automatically',
|
36
|
+
'translated to the languages of your choice through ChatGPT'
|
37
|
+
].join(' ')
|
38
|
+
s.authors = ['Yegor Bugayenko']
|
39
|
+
s.email = 'yegor256@gmail.com'
|
40
|
+
s.homepage = 'https://github.com/yegor256/jekyll-chatgpt-translate'
|
41
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
42
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
43
|
+
s.rdoc_options = ['--charset=UTF-8']
|
44
|
+
s.extra_rdoc_files = %w[README.md LICENSE.txt]
|
45
|
+
s.add_runtime_dependency 'iso-639', '~> 0.3.6'
|
46
|
+
s.add_runtime_dependency 'jekyll', '~> 3.9.2'
|
47
|
+
s.add_runtime_dependency 'redcarpet', '~> 3.6.0'
|
48
|
+
s.add_runtime_dependency 'ruby-openai', '~> 5.0.0'
|
49
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
50
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'jekyll'
|
26
|
+
require 'openai'
|
27
|
+
require 'iso-639'
|
28
|
+
|
29
|
+
# The module we are in.
|
30
|
+
module GptTranslate; end
|
31
|
+
|
32
|
+
# Abstraction of ChatGPT.
|
33
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
34
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
35
|
+
# License:: MIT
|
36
|
+
class GptTranslate::ChatGPT
|
37
|
+
# Ctor.
|
38
|
+
# +key+ OpenAI API Key, which can't be nil, but can be empty string, which means dry mode (no calls to OpenAI)
|
39
|
+
# +source+ The language to translate from
|
40
|
+
# +target+ The language to translate into
|
41
|
+
def initialize(key, source, target)
|
42
|
+
raise 'OpenAI key cannot be nil' if key.nil?
|
43
|
+
@key = key
|
44
|
+
@source = source
|
45
|
+
@target = target
|
46
|
+
end
|
47
|
+
|
48
|
+
def translate(text)
|
49
|
+
model = 'gpt-3.5-turbo'
|
50
|
+
text.split("\n\n").compact.map do |par|
|
51
|
+
if par.length <= 32
|
52
|
+
Jekyll.logger.debug("Not translating this, b/c too short: \"#{par}\"")
|
53
|
+
par
|
54
|
+
elsif par !~ /^[А-Я]/
|
55
|
+
Jekyll.logger.debug("Not translating this, b/c it's not a plain text: \"#{par}\"")
|
56
|
+
par
|
57
|
+
elsif @key.empty?
|
58
|
+
par
|
59
|
+
else
|
60
|
+
translate_par(par, model)
|
61
|
+
end
|
62
|
+
end.join("\n\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def translate_par(par, model)
|
68
|
+
Time.now
|
69
|
+
t = nil
|
70
|
+
attempt = 0
|
71
|
+
begin
|
72
|
+
response = OpenAI::Client.new(access_token: @key).chat(
|
73
|
+
parameters: {
|
74
|
+
model: model,
|
75
|
+
messages: [{
|
76
|
+
role: 'user',
|
77
|
+
content: "#{prompt}:\n\n#{par}"
|
78
|
+
}],
|
79
|
+
temperature: 0.7
|
80
|
+
}
|
81
|
+
)
|
82
|
+
t = response.dig('choices', 0, 'message', 'content')
|
83
|
+
rescue StandardError
|
84
|
+
attempt += 1
|
85
|
+
retry if attempt < 4
|
86
|
+
end
|
87
|
+
if t.nil?
|
88
|
+
Jekyll.logger.error("Failed to translate #{par.split.count}
|
89
|
+
#{@source.upcase} words after #{attempt} attempts :(")
|
90
|
+
'FAILED TO TRANSLATE THIS PARAGRAPH'
|
91
|
+
else
|
92
|
+
Jekyll.logger.debug("Translated #{par.split.count} #{@source.upcase} words
|
93
|
+
to #{t.split.count} #{@target.upcase} words
|
94
|
+
through #{model} in #{(Time.now - pstart).round(2)}s")
|
95
|
+
t
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def prompt
|
100
|
+
if (source == 'ru') && (target == 'en')
|
101
|
+
'Пожалуйста, переведи этот параграф на английский язык'
|
102
|
+
elsif (source == 'en') && (target == 'ru')
|
103
|
+
'Please, translate this paragraph to Russian'
|
104
|
+
else
|
105
|
+
[
|
106
|
+
'Please, translate this paragraph from',
|
107
|
+
ISO_639.find_by_code(@source),
|
108
|
+
'to',
|
109
|
+
ISO_639.find_by_code(@target)
|
110
|
+
].join(' ')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'jekyll'
|
26
|
+
require_relative 'chatgpt'
|
27
|
+
require_relative 'plain'
|
28
|
+
|
29
|
+
# The module we are in.
|
30
|
+
module GptTranslate; end
|
31
|
+
|
32
|
+
# Pages generator.
|
33
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
34
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
35
|
+
# License:: MIT
|
36
|
+
class GptTranslate::Generator < Jekyll::Generator
|
37
|
+
safe true
|
38
|
+
priority :lowest
|
39
|
+
|
40
|
+
# Main plugin action, called by Jekyll-core
|
41
|
+
def generate(site)
|
42
|
+
@site = site
|
43
|
+
key = ENV.fetch('OPENAI_API_KEY', nil)
|
44
|
+
if key.nil? && Jekyll.env == 'development'
|
45
|
+
Jekyll.logger.info('OPENAI_API_KEY environment variable is not set and
|
46
|
+
we are in development mode, no actual translation will happen,
|
47
|
+
but pages will be generated')
|
48
|
+
key = ''
|
49
|
+
end
|
50
|
+
if key.nil?
|
51
|
+
Jekyll.logger.info('jekyll-chatgpt-translate requires OPENAI_API_KEY environment variable')
|
52
|
+
return
|
53
|
+
end
|
54
|
+
layout = config['layout'] || 'translated'
|
55
|
+
start = Time.now
|
56
|
+
total = 0
|
57
|
+
site.posts.docs.each do |doc|
|
58
|
+
plain = GptTranslate::Plain.new(doc.content).to_s
|
59
|
+
config['targets'].each do |target|
|
60
|
+
lang = target['language']
|
61
|
+
raise 'Language must be defined for each target' if target.nil?
|
62
|
+
gpt = GptTranslate::ChatGPT.new(key, config['source'] || 'en', lang)
|
63
|
+
translated = gpt.translate(plain)
|
64
|
+
path = "_chatgpt-translated/#{doc.basename}"
|
65
|
+
FileUtils.mkdir_p(File.dirname(path))
|
66
|
+
File.write(
|
67
|
+
path,
|
68
|
+
[
|
69
|
+
'---',
|
70
|
+
"layout: #{target['layout'] || layout}",
|
71
|
+
"title: #{doc.data['title']}",
|
72
|
+
"permalink: #{permalink(doc, target['permalink'])}",
|
73
|
+
'---',
|
74
|
+
'',
|
75
|
+
translated
|
76
|
+
].join("\n")
|
77
|
+
)
|
78
|
+
site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
|
79
|
+
total += 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
puts "#{total} pages generated in #{(Time.now - start).round(2)}s"
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Returns the plugin's config or an empty hash if not set
|
88
|
+
def config
|
89
|
+
@config ||= @site.config['chatgpt-translate'] || {}
|
90
|
+
end
|
91
|
+
|
92
|
+
def permalink(doc, template)
|
93
|
+
raise 'permalink must be defined for each target' if template.nil?
|
94
|
+
template
|
95
|
+
.gsub(':year', format('%04d', doc['date'].year))
|
96
|
+
.gsub(':month', format('%02d', doc['date'].month))
|
97
|
+
.gsub(':day', format('%02d', doc['date'].day))
|
98
|
+
.gsub(':title', doc['title'])
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'redcarpet'
|
26
|
+
|
27
|
+
# The module we are in.
|
28
|
+
module GptTranslate; end
|
29
|
+
|
30
|
+
# Markdown to plain text.
|
31
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
33
|
+
# License:: MIT
|
34
|
+
class GptTranslate::Plain
|
35
|
+
# Ctor.
|
36
|
+
def initialize(markdown)
|
37
|
+
@markdown = markdown
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
@markdown.split(/\n{2,}/).compact.map do |par|
|
42
|
+
par.gsub!("\n", ' ')
|
43
|
+
par.gsub!(/\s{2,}/, ' ')
|
44
|
+
par.strip!
|
45
|
+
next if par.start_with?('<')
|
46
|
+
next if par.start_with?('{%')
|
47
|
+
Redcarpet::Markdown.new(Strip).render(par)
|
48
|
+
end.join("\n\n").gsub(/\n{2,}/, "\n\n").strip
|
49
|
+
end
|
50
|
+
|
51
|
+
# Markdown to pain text.
|
52
|
+
class Strip < Redcarpet::Render::Base
|
53
|
+
%i[
|
54
|
+
block_code block_quote
|
55
|
+
block_html
|
56
|
+
autolink codespan double_emphasis
|
57
|
+
emphasis underline raw_html
|
58
|
+
triple_emphasis strikethrough
|
59
|
+
superscript highlight quote
|
60
|
+
footnotes footnote_def footnote_ref
|
61
|
+
entity normal_text
|
62
|
+
].each do |method|
|
63
|
+
define_method method do |*args|
|
64
|
+
args.first
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def list(content, _type)
|
69
|
+
content
|
70
|
+
end
|
71
|
+
|
72
|
+
def list_item(content, _type)
|
73
|
+
content
|
74
|
+
end
|
75
|
+
|
76
|
+
def paragraph(text)
|
77
|
+
text
|
78
|
+
end
|
79
|
+
|
80
|
+
def link(_link, _title, content)
|
81
|
+
content
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
module Jekyll::Translate
|
26
|
+
VERSION = '0.0.1'
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'jekyll-chatgpt-translate/generator'
|
data/renovate.json
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2023 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 NONINFINGEMENT. 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
|
+
$stdout.sync = true
|
24
|
+
|
25
|
+
require 'simplecov'
|
26
|
+
SimpleCov.start
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative '../lib/jekyll-chatgpt-translate/chatgpt'
|
27
|
+
|
28
|
+
# ChatGPT test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class GptTranslate::ChatGPTTest < Minitest::Test
|
33
|
+
def test_short_text
|
34
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'en', 'ru')
|
35
|
+
assert_equal('Hello, world!', chat.translate('Hello, world!'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_dry_mode
|
39
|
+
chat = GptTranslate::ChatGPT.new('', 'en', 'ru')
|
40
|
+
assert_equal(38, chat.translate('This text should not be sent to OpenAI').length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_markup
|
44
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'en', 'ru')
|
45
|
+
assert_equal('<img src="a"/>', chat.translate('<img src="a"/>'))
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative '../lib/jekyll-chatgpt-translate/generator'
|
27
|
+
|
28
|
+
# Generator test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class GptTranslate::GeneratorTest < Minitest::Test
|
33
|
+
def test_simple_scenario
|
34
|
+
# assert(stdout.include?('DEBUG'))
|
35
|
+
end
|
36
|
+
end
|
data/test/test_plain.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (The MIT License)
|
4
|
+
#
|
5
|
+
# Copyright (c) 2023 Yegor Bugayenko
|
6
|
+
#
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
12
|
+
# furnished to do so, subject to the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
15
|
+
# copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
# SOFTWARE.
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require_relative '../lib/jekyll-chatgpt-translate/plain'
|
27
|
+
|
28
|
+
# Plain test.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class GptTranslate::PlainTest < Minitest::Test
|
33
|
+
def test_simple_map
|
34
|
+
assert_equal('Hello, world!', GptTranslate::Plain.new('Hello, **world**!').to_s)
|
35
|
+
assert_equal('Hello, Jeff!', GptTranslate::Plain.new('Hello, _Jeff_!').to_s)
|
36
|
+
assert_equal("Hi\n\nBye", GptTranslate::Plain.new(" Hi\n\nBye\n\n\n").to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_lists
|
40
|
+
assert_equal(
|
41
|
+
"first\n\nsecond\n\nthird",
|
42
|
+
GptTranslate::Plain.new("* first\n\n* second\n\n* third").to_s
|
43
|
+
)
|
44
|
+
assert_equal(
|
45
|
+
'first',
|
46
|
+
GptTranslate::Plain.new("* first\n\n\n\n").to_s
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_links
|
51
|
+
assert_equal(
|
52
|
+
'Hello, dude!',
|
53
|
+
GptTranslate::Plain.new('Hello, [dude](https://www.google.com)!').to_s
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-chatgpt-translate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yegor Bugayenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: iso-639
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jekyll
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.9.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.9.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redcarpet
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.6.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-openai
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.0.0
|
69
|
+
description: Add this plugin to your Jekyll site and all posts will be automatically
|
70
|
+
translated to the languages of your choice through ChatGPT
|
71
|
+
email: yegor256@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- LICENSE.txt
|
77
|
+
files:
|
78
|
+
- ".0pdd.yml"
|
79
|
+
- ".github/workflows/rake.yml"
|
80
|
+
- ".gitignore"
|
81
|
+
- ".pdd"
|
82
|
+
- ".rubocop.yml"
|
83
|
+
- ".rultor.yml"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- features/cli.feature
|
89
|
+
- features/gem_package.feature
|
90
|
+
- features/step_definitions/steps.rb
|
91
|
+
- features/support/env.rb
|
92
|
+
- jekyll-chatgpt-translate.gemspec
|
93
|
+
- lib/jekyll-chatgpt-translate.rb
|
94
|
+
- lib/jekyll-chatgpt-translate/chatgpt.rb
|
95
|
+
- lib/jekyll-chatgpt-translate/generator.rb
|
96
|
+
- lib/jekyll-chatgpt-translate/plain.rb
|
97
|
+
- lib/jekyll-chatgpt-translate/version.rb
|
98
|
+
- renovate.json
|
99
|
+
- test/test__helper.rb
|
100
|
+
- test/test_chatgpt.rb
|
101
|
+
- test/test_generator.rb
|
102
|
+
- test/test_plain.rb
|
103
|
+
homepage: https://github.com/yegor256/jekyll-chatgpt-translate
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata:
|
107
|
+
rubygems_mfa_required: 'true'
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options:
|
110
|
+
- "--charset=UTF-8"
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.6'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubygems_version: 3.2.15
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Translate Jekyll Pages Through ChatGPT
|
128
|
+
test_files: []
|