jekyll-chatgpt-translate 0.0.17 → 0.0.18
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 +4 -4
- data/README.md +7 -0
- data/features/step_definitions/steps.rb +6 -10
- data/jekyll-chatgpt-translate.gemspec +1 -1
- data/lib/jekyll-chatgpt-translate/generator.rb +33 -32
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_generator.rb +6 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f593e5927f89dc9fe25dcbe28cc61ed938b3fdc42aee742d9ec31ebc86417fe
|
4
|
+
data.tar.gz: c5486a9adaf6e838bd016ea01175169786dbdd1807601cf922b0acc065c0a337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 794664182ebba232506ab97b026d02a7060ee369fb16756308d43362df24aed862703836fb0af142c07240fd1eeeeeb9305e43804ed5b34300ce2dff1c30a03c
|
7
|
+
data.tar.gz: f1db90b466e6ea441519ee35351a2bf62b9182ed772ab020b5cd4692fc8932a22115fb994089b1cb70724c92a4344865810312b7a58fe1fe666ba0e5c308aaeb
|
data/README.md
CHANGED
@@ -50,6 +50,8 @@ to get the URL of the page that was translated.
|
|
50
50
|
|
51
51
|
You can also use `{{ page.chatgpt-model }}`
|
52
52
|
inside both the original page and the translated one, to refer to the model of ChatGPT.
|
53
|
+
The presence of this attribute in the `{{ page }}` means that the
|
54
|
+
page was translated or the translated HTML was downloaded and placed into the `_site` directory.
|
53
55
|
|
54
56
|
## Options
|
55
57
|
|
@@ -62,6 +64,11 @@ Full list of options available to specify in `_config.yml`:
|
|
62
64
|
|
63
65
|
* `source` (optional) — is the ISO-839-1 code of the source language.
|
64
66
|
|
67
|
+
* `no_download` (optional) — if this attribute is present, the plugin won't try
|
68
|
+
to find HTML versions of translated pages in the Internet and won't try to
|
69
|
+
download them and place into the `_site` directory. Thus, your entire site
|
70
|
+
will have to be re-translated on every build (might be very ineffective if the site is big!)
|
71
|
+
|
65
72
|
* `layout` (optional) — is name of the file in `_layouts` directory, without the extension.
|
66
73
|
This layout will be specified for the pages generated by this plugin.
|
67
74
|
|
@@ -40,7 +40,7 @@ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
|
|
40
40
|
File.write(file, text.gsub('\\xFF', 0xFF.chr))
|
41
41
|
end
|
42
42
|
|
43
|
-
When(
|
43
|
+
When('I build Jekyll site') do
|
44
44
|
@stdout = `jekyll build`
|
45
45
|
@exitstatus = $CHILD_STATUS.exitstatus
|
46
46
|
end
|
@@ -59,20 +59,16 @@ Then('File {string} contains {string}') do |string, string2|
|
|
59
59
|
raise "The file \"#{string}\" doesn't contain \"#{string2}\":\n#{content}" unless content.include?(string2)
|
60
60
|
end
|
61
61
|
|
62
|
-
Then(
|
63
|
-
raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
|
64
|
-
end
|
65
|
-
|
66
|
-
Then(/^Exit code is zero$/) do
|
62
|
+
Then('Exit code is zero') do
|
67
63
|
raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
|
68
64
|
end
|
69
65
|
|
70
|
-
Then(
|
66
|
+
Then('Exit code is not zero') do
|
71
67
|
raise 'Zero exit code' if @exitstatus.zero?
|
72
68
|
end
|
73
69
|
|
74
|
-
When(
|
75
|
-
@stdout = `#{
|
70
|
+
When('I run bash with {string}') do |string|
|
71
|
+
@stdout = `#{string}`
|
76
72
|
@exitstatus = $CHILD_STATUS.exitstatus
|
77
73
|
end
|
78
74
|
|
@@ -81,7 +77,7 @@ When(/^I run bash with:$/) do |text|
|
|
81
77
|
@exitstatus = $CHILD_STATUS.exitstatus
|
82
78
|
end
|
83
79
|
|
84
|
-
When(
|
80
|
+
When('I copy this gem into temp dir') do
|
85
81
|
FileUtils.copy_entry(@cwd, File.join(@dir, 'jekyll-chatgpt-translate'))
|
86
82
|
end
|
87
83
|
|
@@ -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.18'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -68,41 +68,42 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
68
68
|
FileUtils.mkdir_p(File.dirname(path))
|
69
69
|
File.write(path, '') # in order to surpress warnings in Page ctor
|
70
70
|
dest = Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path)).destination(site.dest)
|
71
|
-
|
72
|
-
doc.data['chatgpt-model'] = model
|
73
|
-
if GptTranslate::Ping.new(site, link).found?(dest, version)
|
71
|
+
if config['no_download'].nil? && GptTranslate::Ping.new(site, link).found?(dest, version)
|
74
72
|
copied += 1
|
73
|
+
elsif translated >= threshold
|
75
74
|
next
|
75
|
+
else
|
76
|
+
gpt = GptTranslate::ChatGPT.new(
|
77
|
+
key,
|
78
|
+
model,
|
79
|
+
config['source'] || 'en',
|
80
|
+
lang
|
81
|
+
)
|
82
|
+
foreign = gpt.translate(plain)
|
83
|
+
File.write(
|
84
|
+
path,
|
85
|
+
[
|
86
|
+
'---',
|
87
|
+
"layout: #{target['layout'] || layout}",
|
88
|
+
"title: #{doc['title'].to_json}",
|
89
|
+
"description: #{doc['description'].to_json}",
|
90
|
+
"permalink: #{link.to_json}",
|
91
|
+
"translated-original-url: #{doc.url.to_json}",
|
92
|
+
"translated-language: #{lang.to_json}",
|
93
|
+
"chatgpt-model: #{model.to_json}",
|
94
|
+
'---',
|
95
|
+
'',
|
96
|
+
foreign,
|
97
|
+
'',
|
98
|
+
"#{marker} on #{Time.now.strftime('%d/%m/%Y %H:%M')}\n{: .jekyll-chatgpt-translate}"
|
99
|
+
].join("\n")
|
100
|
+
)
|
101
|
+
site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
|
102
|
+
translated += 1
|
103
|
+
Jekyll.logger.info("Translated via ChatGPT: #{path} (#{File.size(path)} bytes)")
|
76
104
|
end
|
77
|
-
|
78
|
-
|
79
|
-
key,
|
80
|
-
model,
|
81
|
-
config['source'] || 'en',
|
82
|
-
lang
|
83
|
-
)
|
84
|
-
foreign = gpt.translate(plain)
|
85
|
-
File.write(
|
86
|
-
path,
|
87
|
-
[
|
88
|
-
'---',
|
89
|
-
"layout: #{target['layout'] || layout}",
|
90
|
-
"title: #{doc['title'].to_json}",
|
91
|
-
"description: #{doc['description'].to_json}",
|
92
|
-
"permalink: #{link.to_json}",
|
93
|
-
"translated-original-url: #{doc.url.to_json}",
|
94
|
-
"translated-language: #{lang.to_json}",
|
95
|
-
"chatgpt-model: #{model.to_json}",
|
96
|
-
'---',
|
97
|
-
'',
|
98
|
-
foreign,
|
99
|
-
'',
|
100
|
-
"#{marker} on #{Time.now.strftime('%d/%m/%Y %H:%M')}\n{: .jekyll-chatgpt-translate}"
|
101
|
-
].join("\n")
|
102
|
-
)
|
103
|
-
site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
|
104
|
-
translated += 1
|
105
|
-
Jekyll.logger.info("Translated via ChatGPT: #{path} (#{File.size(path)} bytes)")
|
105
|
+
doc.data["translated-#{lang}-url"] = link
|
106
|
+
doc.data['chatgpt-model'] = model
|
106
107
|
end
|
107
108
|
end
|
108
109
|
Jekyll.logger.info("#{translated} pages translated and #{copied} pages copied in #{(Time.now - start).round(2)}s")
|
data/test/test_generator.rb
CHANGED
@@ -75,28 +75,23 @@ class GptTranslate::GeneratorTest < Minitest::Test
|
|
75
75
|
end
|
76
76
|
|
77
77
|
class FakeDocument
|
78
|
+
attr_reader :data
|
79
|
+
|
78
80
|
def initialize(path)
|
79
81
|
@path = path
|
82
|
+
@data = { 'date' => Time.now, 'title' => 'Hello!' }
|
80
83
|
end
|
81
84
|
|
82
85
|
def content
|
83
86
|
'Hello, world!'
|
84
87
|
end
|
85
88
|
|
86
|
-
def
|
87
|
-
|
89
|
+
def []=(key, value)
|
90
|
+
@data[key] = value
|
88
91
|
end
|
89
92
|
|
90
|
-
def []=(key, value); end
|
91
|
-
|
92
93
|
def [](key)
|
93
|
-
|
94
|
-
Time.now
|
95
|
-
elsif key == 'title'
|
96
|
-
'Hello!'
|
97
|
-
else
|
98
|
-
''
|
99
|
-
end
|
94
|
+
@data[key] || ''
|
100
95
|
end
|
101
96
|
|
102
97
|
def relative_path
|