jekyll-chatgpt-translate 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/README.md +11 -2
- data/jekyll-chatgpt-translate.gemspec +1 -2
- data/lib/jekyll-chatgpt-translate/generator.rb +9 -4
- data/lib/jekyll-chatgpt-translate/plain.rb +4 -3
- data/lib/jekyll-chatgpt-translate/version.rb +1 -1
- data/test/test_plain.rb +8 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c02caba7176953aa1d0df4bbe92e40dcf7f1046b22f9f2af8dcd434179d36a00
|
4
|
+
data.tar.gz: 6d510fbdc601a7f7174194b39a17402e8e3aff08ff40190e8799d897eaf1aded
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4224dd0584ed1d6ed56e876e4678de0dcba0a2338dba08bfa61a3147365ddec617116ed92f4616799b182c127f5d4509ab114e02659ca87dad1cd1e6fe9825c
|
7
|
+
data.tar.gz: ac6ed731ca359ccc2021be00c232c60271a212c0f68dd5ca4e0212ef7ebf6bb26c2a94decae2422fc17c80e5c880e52aea407d175b22a19ae0dd544da4d485e6
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,10 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/jekyll-chatgpt-translate.svg)](http://badge.fury.io/rb/jekyll-chatgpt-translate)
|
5
5
|
|
6
6
|
If you have a [Jekyll](https://jekyllrb.com/) static site, this plugin may help you automatically
|
7
|
-
translate its pages to another language, through [ChatGPT](https://chat.openai.com/).
|
7
|
+
translate its pages to another language, through [ChatGPT](https://chat.openai.com/). See how it
|
8
|
+
works for [my blog](https://github.com/yegor256/ru.yegor256.com),
|
9
|
+
for example [this page](https://ru.yegor256.com/2023-08-13-dictators.html) is translated to
|
10
|
+
[English]().
|
8
11
|
|
9
12
|
Install it first:
|
10
13
|
|
@@ -39,7 +42,8 @@ You can get your key [here](https://help.openai.com/en/articles/4936850-where-do
|
|
39
42
|
Inside the original page you can use `{{ page.translated-XX-url }}` in order to render the URL
|
40
43
|
of the translated page, where `XX` is the ISO-839-1 code of the target language..
|
41
44
|
Inside the translated page you can use `{{ page.translated-original-url }}` in order
|
42
|
-
to get the URL of the page that was translated.
|
45
|
+
to get the URL of the page that was translated. You can also use `{{ page.chatgpt-model }}`
|
46
|
+
inside both the original page and the translated one, to refer to the model of ChatGPT.
|
43
47
|
|
44
48
|
## Options
|
45
49
|
|
@@ -65,6 +69,11 @@ This layout will be specified for the pages generated by this plugin.
|
|
65
69
|
|
66
70
|
* `threshold` (optional) — maximum number of pages to generate in one build cycle.
|
67
71
|
|
72
|
+
* `version` (optional) — the version that will be attached to each generated page,
|
73
|
+
in order to avoid repetitive translations on one hand and enable re-translations
|
74
|
+
when the `version` is changed on another hand. By default, the version of
|
75
|
+
the plugin will be used here, unless you set your own value.
|
76
|
+
|
68
77
|
## How to Contribute
|
69
78
|
|
70
79
|
Make a fork and then test it locally like this:
|
@@ -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.11'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -45,7 +45,6 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.add_runtime_dependency 'iri', '>= 0'
|
46
46
|
s.add_runtime_dependency 'iso-639', '>= 0'
|
47
47
|
s.add_runtime_dependency 'jekyll', '>= 3'
|
48
|
-
s.add_runtime_dependency 'liquid', '>= 4'
|
49
48
|
s.add_runtime_dependency 'redcarpet', '>= 3'
|
50
49
|
s.add_runtime_dependency 'ruby-openai', '>= 5'
|
51
50
|
s.metadata['rubygems_mfa_required'] = 'true'
|
@@ -50,6 +50,7 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
50
50
|
return
|
51
51
|
end
|
52
52
|
layout = config['layout'] || 'translated'
|
53
|
+
version = config['version'] || GptTranslate::VERSION
|
53
54
|
threshold = config['threshold'] || 1_000_000_000
|
54
55
|
start = Time.now
|
55
56
|
total = 0
|
@@ -82,14 +83,16 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
82
83
|
"title: #{doc.data['title']}",
|
83
84
|
"permalink: #{link}",
|
84
85
|
"translated-original-url: #{doc.url}",
|
86
|
+
"chatgpt-model: #{model}",
|
85
87
|
'---',
|
86
88
|
'',
|
87
89
|
translated,
|
88
90
|
'',
|
89
|
-
"Translated by ChatGPT #{model}/#{
|
91
|
+
"Translated by ChatGPT #{model}/#{version}\n{: .jekyll-chatgpt-translate}"
|
90
92
|
].join("\n")
|
91
93
|
)
|
92
94
|
doc.data["translated-#{lang}-url"] = link
|
95
|
+
doc.data['chatgpt-model'] = model
|
93
96
|
site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
|
94
97
|
total += 1
|
95
98
|
Jekyll.logger.info("Translated via ChatGPT: #{path}")
|
@@ -110,10 +113,12 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
110
113
|
Jekyll.logger.info('The key is found in the OPENAI_API_KEY env variable') unless k.nil?
|
111
114
|
k
|
112
115
|
elsif File.exist?(file)
|
113
|
-
|
114
|
-
|
116
|
+
k = File.read(file).strip
|
117
|
+
Jekyll.logger.info("The OpenAI API key taken from the file: \"#{file}\" (#{k.length} chars)")
|
118
|
+
k
|
115
119
|
else
|
116
|
-
Jekyll.logger.info("The file is not found: #{file}")
|
120
|
+
Jekyll.logger.info("The file with the OpenAI API key is not found: \"#{file}\"")
|
121
|
+
nil
|
117
122
|
end
|
118
123
|
if key.nil? && Jekyll.env == 'development'
|
119
124
|
Jekyll.logger.info("OPENAI_API_KEY environment variable is not set, \
|
@@ -23,7 +23,6 @@
|
|
23
23
|
# SOFTWARE.
|
24
24
|
|
25
25
|
require 'redcarpet'
|
26
|
-
require 'liquid'
|
27
26
|
|
28
27
|
# The module we are in.
|
29
28
|
module GptTranslate; end
|
@@ -42,9 +41,11 @@ class GptTranslate::Plain
|
|
42
41
|
@markdown.split(/\n{2,}/).compact.map do |par|
|
43
42
|
par.gsub!("\n", ' ')
|
44
43
|
par.gsub!(/\s{2,}/, ' ')
|
44
|
+
# Liquid tags are removed, but this implementation is primitive
|
45
|
+
# Seehttps://stackoverflow.com/questions/
|
46
|
+
par.gsub!(/{{[^}]+}}/, '')
|
47
|
+
par.gsub!(/{%[^%]+%}/, '')
|
45
48
|
par.strip!
|
46
|
-
liquid = Liquid::Template.parse(par)
|
47
|
-
par = liquid.render({}, drop: NullDrop.new, registers: { removed: true })
|
48
49
|
Redcarpet::Markdown.new(Strip).render(par)
|
49
50
|
end.join("\n\n").gsub(/\n{2,}/, "\n\n").strip
|
50
51
|
end
|
data/test/test_plain.rb
CHANGED
@@ -81,5 +81,13 @@ class GptTranslate::PlainTest < Minitest::Test
|
|
81
81
|
'Hello, !',
|
82
82
|
GptTranslate::Plain.new('Hello, {{ Java }}!').to_s
|
83
83
|
)
|
84
|
+
assert_equal(
|
85
|
+
'Hello, dude !',
|
86
|
+
GptTranslate::Plain.new('Hello, {% if a %} dude {% endif %}!').to_s
|
87
|
+
)
|
88
|
+
assert_equal(
|
89
|
+
'Hello, !',
|
90
|
+
GptTranslate::Plain.new('Hello, {% Java %}!').to_s
|
91
|
+
)
|
84
92
|
end
|
85
93
|
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.11
|
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-08-
|
11
|
+
date: 2023-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iri
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: liquid
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '4'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: redcarpet
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|