jekyll-chatgpt-translate 0.0.32 → 0.0.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +3 -2
- data/lib/jekyll-chatgpt-translate/pars.rb +54 -0
- data/lib/jekyll-chatgpt-translate/ping.rb +1 -2
- data/lib/jekyll-chatgpt-translate/plain.rb +1 -1
- data/lib/jekyll-chatgpt-translate/prompt.rb +5 -1
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_pars.rb +70 -0
- data/test/test_plain.rb +7 -0
- data/test/test_prompt.rb +5 -5
- 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: f382405857f236d2b59e129760b41f49efd2815b8ebcffab87bf8d92f89c40a6
|
4
|
+
data.tar.gz: 65897a2650943260e087213ae42baaee18cf34d6a163d90e7ba5348dd3c46a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebbc5c28294a0a69b9a0cf3ee08ee7cf84ff9eb609e8efde9549b02f11e653236deebe371e6506fefa78156a229c8deeaab7f0af13e4caa0f1e108205971ec51
|
7
|
+
data.tar.gz: 7de6d8bd8e966b3b0a4c322092dbaf0e38620e56d89ff1400f48f7a2199475133f095d18bec467bbe01c8fb12b63f13f982cc86d0376fe458631db22a82c6ecf
|
data/.github/workflows/rake.yml
CHANGED
data/Gemfile
CHANGED
@@ -25,11 +25,11 @@
|
|
25
25
|
source 'https://rubygems.org'
|
26
26
|
gemspec
|
27
27
|
|
28
|
-
gem 'cucumber', '
|
28
|
+
gem 'cucumber', '9.0.1', require: false
|
29
29
|
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
30
30
|
gem 'minitest', '5.19.0', require: false
|
31
31
|
gem 'rake', '13.0.6', require: false
|
32
32
|
gem 'rubocop', '1.56.2', require: false
|
33
33
|
gem 'rubocop-rspec', '2.23.2', require: false
|
34
34
|
gem 'simplecov', '0.22.0', require: false
|
35
|
-
gem 'webmock', '3.
|
35
|
+
gem 'webmock', '3.19.1', require: false
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ to get the URL of the page that was translated.
|
|
50
50
|
|
51
51
|
You can also use `{{ page.chatgpt-translate.model }}`
|
52
52
|
inside both the original page and the translated one, to refer to the model of ChatGPT.
|
53
|
-
The presence of
|
53
|
+
The presence of `{{ page.chatgpt-translate }}` means that the
|
54
54
|
page was translated or the translated HTML was downloaded and placed into the `_site` directory.
|
55
55
|
|
56
56
|
## Options
|
@@ -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 = '>= 2.6'
|
30
30
|
s.name = 'jekyll-chatgpt-translate'
|
31
|
-
s.version = '0.0.
|
31
|
+
s.version = '0.0.34'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -25,6 +25,7 @@
|
|
25
25
|
require 'jekyll'
|
26
26
|
require 'openai'
|
27
27
|
require 'iso-639'
|
28
|
+
require_relative 'pars'
|
28
29
|
require_relative 'prompt'
|
29
30
|
|
30
31
|
# The module we are in.
|
@@ -51,7 +52,7 @@ class GptTranslate::ChatGPT
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def translate(markdown, min: 32)
|
54
|
-
|
55
|
+
GptTranslate::Pars.new(markdown).to_a.map do |par|
|
55
56
|
par.strip!
|
56
57
|
if @source == @target
|
57
58
|
Jekyll.logger.debug("No need to translate from #{@source.inspect} to #{@target.inspect}: #{par.inspect}")
|
@@ -59,7 +60,7 @@ class GptTranslate::ChatGPT
|
|
59
60
|
elsif par.length < min
|
60
61
|
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
|
61
62
|
par
|
62
|
-
elsif par.start_with?('```')
|
63
|
+
elsif par.start_with?('```')
|
63
64
|
Jekyll.logger.debug("Not translating this code block: #{par.inspect}")
|
64
65
|
par
|
65
66
|
elsif par =~ /^[^\p{Alnum}\*'"\[]/
|
@@ -0,0 +1,54 @@
|
|
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
|
+
# The module we are in.
|
26
|
+
module GptTranslate; end
|
27
|
+
|
28
|
+
# Markdown broken down ito pars.
|
29
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# License:: MIT
|
32
|
+
class GptTranslate::Pars
|
33
|
+
# Ctor.
|
34
|
+
# +markdown+ The markdown
|
35
|
+
def initialize(markdown)
|
36
|
+
@markdown = markdown
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns an array of strings
|
40
|
+
def to_a
|
41
|
+
pars = []
|
42
|
+
inside = false
|
43
|
+
@markdown.strip.split(/\n{2,}/).compact.each do |par|
|
44
|
+
if inside
|
45
|
+
pars[pars.size - 1] = "#{pars[pars.size - 1]}\n\n#{par}"
|
46
|
+
else
|
47
|
+
pars << par
|
48
|
+
end
|
49
|
+
inside = true if par.start_with?('```') && !inside
|
50
|
+
inside = false if par.end_with?('```') && inside
|
51
|
+
end
|
52
|
+
pars
|
53
|
+
end
|
54
|
+
end
|
@@ -57,8 +57,7 @@ class GptTranslate::Ping
|
|
57
57
|
html = response.body if response.is_a?(Net::HTTPSuccess)
|
58
58
|
Jekyll.logger.debug("GET #{uri.inspect}: #{response.code}")
|
59
59
|
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL => e
|
60
|
-
Jekyll.logger.debug("Failed to ping #{uri.inspect}: #{e.message}")
|
61
|
-
Jekyll.logger.info("The page is absent (#{e.class.name}): #{uri.inspect}")
|
60
|
+
Jekyll.logger.debug("Failed to ping #{uri.inspect} (#{e.class.name}): #{e.message}")
|
62
61
|
end
|
63
62
|
html
|
64
63
|
end
|
@@ -42,7 +42,7 @@ class GptTranslate::Plain
|
|
42
42
|
def to_s
|
43
43
|
Redcarpet::Markdown.new(Strip).render(
|
44
44
|
@markdown
|
45
|
-
.gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2")
|
45
|
+
.gsub(/([^\n])\n(\s*\* )/, "\\1\n\n\\2") # condensed list into item-per-par
|
46
46
|
.gsub(/<!--.+?-->/m, '')
|
47
47
|
.gsub(/{{[^}]+}}/, '')
|
48
48
|
.gsub(/{%.+?%}/, '')
|
@@ -54,6 +54,10 @@ class GptTranslate::Prompt
|
|
54
54
|
to[3],
|
55
55
|
', don\'t translate technical terms and proper nouns'
|
56
56
|
].join
|
57
|
-
"
|
57
|
+
if @par.include?('"') || @par.split.count >= 8
|
58
|
+
"#{head}:\n\n#{@par}"
|
59
|
+
else
|
60
|
+
"#{head}: \"#{@par}\""
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
data/test/test_pars.rb
ADDED
@@ -0,0 +1,70 @@
|
|
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 'test__helper'
|
27
|
+
require_relative '../lib/jekyll-chatgpt-translate/pars'
|
28
|
+
|
29
|
+
# Test for Pars.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class GptTranslate::ParsTest < Minitest::Test
|
34
|
+
def test_simple_cases
|
35
|
+
assert_equal(1, GptTranslate::Pars.new('Hello, **world**!').to_a.size)
|
36
|
+
assert_equal(2, GptTranslate::Pars.new("Hello,\n\n**world**!").to_a.size)
|
37
|
+
assert_equal(2, GptTranslate::Pars.new("\n\n\nHello,\n\n**world**\n!\n\n").to_a.size)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_understands_code_block
|
41
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```java\na\n\nb\n\nc\n```\n\nz").to_a
|
42
|
+
assert_equal(3, pars.size)
|
43
|
+
assert_equal('Hello:', pars[0])
|
44
|
+
assert_equal("```java\na\n\nb\n\nc\n```", pars[1])
|
45
|
+
assert_equal('z', pars[2])
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_understands_empty_block
|
49
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```\n```\n\nz").to_a
|
50
|
+
assert_equal(3, pars.size)
|
51
|
+
assert_equal('Hello:', pars[0])
|
52
|
+
assert_equal("```\n```", pars[1])
|
53
|
+
assert_equal('z', pars[2])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_understands_empty_block_with_type
|
57
|
+
pars = GptTranslate::Pars.new("Hello:\n\n```java\n```\n\nz").to_a
|
58
|
+
assert_equal(3, pars.size)
|
59
|
+
assert_equal('Hello:', pars[0])
|
60
|
+
assert_equal("```java\n```", pars[1])
|
61
|
+
assert_equal('z', pars[2])
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_understands_two_blocks
|
65
|
+
pars = GptTranslate::Pars.new("```java\na\n\nb\n```\n\n```text\na\n\nb\n```").to_a
|
66
|
+
assert_equal(2, pars.size)
|
67
|
+
assert_equal("```java\na\n\nb\n```", pars[0])
|
68
|
+
assert_equal("```text\na\n\nb\n```", pars[1])
|
69
|
+
end
|
70
|
+
end
|
data/test/test_plain.rb
CHANGED
@@ -111,6 +111,13 @@ class GptTranslate::PlainTest < Minitest::Test
|
|
111
111
|
)
|
112
112
|
end
|
113
113
|
|
114
|
+
def test_code_block_with_empty_lines_inside
|
115
|
+
assert_equal(
|
116
|
+
"```\n\nhello\n\nworld!\n\n```",
|
117
|
+
GptTranslate::Plain.new("```\n\nhello\n\n\n\nworld!\n\n```").to_s
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
114
121
|
def test_titles
|
115
122
|
assert_equal('# Hello', GptTranslate::Plain.new('# Hello').to_s)
|
116
123
|
assert_equal('## Hello', GptTranslate::Plain.new('## Hello').to_s)
|
data/test/test_prompt.rb
CHANGED
@@ -31,24 +31,24 @@ require_relative '../lib/jekyll-chatgpt-translate/prompt'
|
|
31
31
|
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class GptTranslate::PromptTest < Minitest::Test
|
34
|
-
def
|
34
|
+
def head(source, target)
|
35
35
|
[
|
36
36
|
'Please, translate the following Markdown paragraph',
|
37
37
|
" from #{source} to #{target},",
|
38
|
-
" don't translate technical terms and proper nouns
|
38
|
+
" don't translate technical terms and proper nouns"
|
39
39
|
].join
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_english_to_russian
|
43
43
|
assert_equal(
|
44
|
-
|
45
|
-
GptTranslate::Prompt.new('Hello, dude
|
44
|
+
"#{head('English', 'Russian')}:\n\nHello, dude, how are you doing today in this fair city?",
|
45
|
+
GptTranslate::Prompt.new('Hello, dude, how are you doing today in this fair city?', 'en', 'ru').to_s
|
46
46
|
)
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_english_to_chinese
|
50
50
|
assert_equal(
|
51
|
-
|
51
|
+
"#{head('English', 'Chinese')}: \"Hello, Jeff!\"",
|
52
52
|
GptTranslate::Prompt.new('Hello, Jeff!', 'en', 'zh').to_s
|
53
53
|
)
|
54
54
|
end
|
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.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iri
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/jekyll-chatgpt-translate.rb
|
108
108
|
- lib/jekyll-chatgpt-translate/chatgpt.rb
|
109
109
|
- lib/jekyll-chatgpt-translate/generator.rb
|
110
|
+
- lib/jekyll-chatgpt-translate/pars.rb
|
110
111
|
- lib/jekyll-chatgpt-translate/permalink.rb
|
111
112
|
- lib/jekyll-chatgpt-translate/ping.rb
|
112
113
|
- lib/jekyll-chatgpt-translate/plain.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- test/test__helper.rb
|
118
119
|
- test/test_chatgpt.rb
|
119
120
|
- test/test_generator.rb
|
121
|
+
- test/test_pars.rb
|
120
122
|
- test/test_permalink.rb
|
121
123
|
- test/test_ping.rb
|
122
124
|
- test/test_plain.rb
|