jekyll-chatgpt-translate 0.0.31 → 0.0.33
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/.rubocop.yml +1 -1
 - data/Gemfile +1 -1
 - data/features/cli.feature +38 -0
 - data/jekyll-chatgpt-translate.gemspec +1 -1
 - data/lib/jekyll-chatgpt-translate/generator.rb +6 -2
 - data/lib/jekyll-chatgpt-translate/ping.rb +1 -2
 - data/lib/jekyll-chatgpt-translate/prompt.rb +5 -1
 - data/lib/jekyll-chatgpt-translate/version.rb +1 -1
 - data/test/test_prompt.rb +5 -5
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: bcbe51d1f51e425e01eeb95267bfe08ebb5e57eba3add1b071fd5ba96b43c0de
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 00d09ef020ba4fea3f6029a3b78d89ce9595428bf4621fa6f20e66f87e6c6266
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8c685004776a719fca54ecfcf4e8a66e27b728ad1af9d2e40efdc9cfd8cf531cbc98d89103089636da67285c2596537b992159de78838d8045016dd622faaf50
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3430c908c2273a2b8c28d628334b4333ed80d61b52498b5dd365e27fec1631a0260fe54bff159e9e1ecc8b669bfb20f464df63d02abcce1f734f31a57d4631e7
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/features/cli.feature
    CHANGED
    
    | 
         @@ -168,3 +168,41 @@ Feature: Simple site building 
     | 
|
| 
       168 
168 
     | 
    
         
             
                And File "_site/2023/01/01/hello.html" contains "/bye.html"
         
     | 
| 
       169 
169 
     | 
    
         
             
                And File "_site/2023/02/02/bye.html" exists
         
     | 
| 
       170 
170 
     | 
    
         
             
                And File "_site/2023/02/02/bye.html" contains "/hello.html"
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
              Scenario: No translation at all
         
     | 
| 
      
 173 
     | 
    
         
            +
                Given I have a "_config.yml" file with content:
         
     | 
| 
      
 174 
     | 
    
         
            +
                """
         
     | 
| 
      
 175 
     | 
    
         
            +
                url: https://www.yegor256.com
         
     | 
| 
      
 176 
     | 
    
         
            +
                markdown: kramdown
         
     | 
| 
      
 177 
     | 
    
         
            +
                plugins:
         
     | 
| 
      
 178 
     | 
    
         
            +
                  - jekyll-chatgpt-translate
         
     | 
| 
      
 179 
     | 
    
         
            +
                chatgpt-translate:
         
     | 
| 
      
 180 
     | 
    
         
            +
                  source: en
         
     | 
| 
      
 181 
     | 
    
         
            +
                  threshold: 0
         
     | 
| 
      
 182 
     | 
    
         
            +
                  api_key: "it-is-not-used, because EN to EN translation"
         
     | 
| 
      
 183 
     | 
    
         
            +
                  layout: default
         
     | 
| 
      
 184 
     | 
    
         
            +
                  targets:
         
     | 
| 
      
 185 
     | 
    
         
            +
                    -
         
     | 
| 
      
 186 
     | 
    
         
            +
                      language: en
         
     | 
| 
      
 187 
     | 
    
         
            +
                      permalink: :slug.html
         
     | 
| 
      
 188 
     | 
    
         
            +
                """
         
     | 
| 
      
 189 
     | 
    
         
            +
                And I have a "_layouts/default.html" file with content:
         
     | 
| 
      
 190 
     | 
    
         
            +
                """
         
     | 
| 
      
 191 
     | 
    
         
            +
                {{ content }}
         
     | 
| 
      
 192 
     | 
    
         
            +
                """
         
     | 
| 
      
 193 
     | 
    
         
            +
                And I have a "_posts/2023-01-01-hello.md" file with content:
         
     | 
| 
      
 194 
     | 
    
         
            +
                """
         
     | 
| 
      
 195 
     | 
    
         
            +
                ---
         
     | 
| 
      
 196 
     | 
    
         
            +
                title: foo
         
     | 
| 
      
 197 
     | 
    
         
            +
                ---
         
     | 
| 
      
 198 
     | 
    
         
            +
                {% if page.chatgpt-translate.model %}
         
     | 
| 
      
 199 
     | 
    
         
            +
                TRANSLATED :(
         
     | 
| 
      
 200 
     | 
    
         
            +
                {% else %}
         
     | 
| 
      
 201 
     | 
    
         
            +
                NO TRANSLATION! :)
         
     | 
| 
      
 202 
     | 
    
         
            +
                {% endif %}
         
     | 
| 
      
 203 
     | 
    
         
            +
                """
         
     | 
| 
      
 204 
     | 
    
         
            +
                Then I build Jekyll site
         
     | 
| 
      
 205 
     | 
    
         
            +
                And Exit code is zero
         
     | 
| 
      
 206 
     | 
    
         
            +
                And Stdout contains "The page is absent, need to translate"
         
     | 
| 
      
 207 
     | 
    
         
            +
                And File "_site/2023/01/01/hello.html" exists
         
     | 
| 
      
 208 
     | 
    
         
            +
                And File "_site/2023/01/01/hello.html" contains "NO TRANSLATION!"
         
     | 
| 
         @@ -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.33'
         
     | 
| 
       32 
32 
     | 
    
         
             
              s.license = 'MIT'
         
     | 
| 
       33 
33 
     | 
    
         
             
              s.summary = 'Translate Jekyll Pages Through ChatGPT'
         
     | 
| 
       34 
34 
     | 
    
         
             
              s.description = [
         
     | 
| 
         @@ -60,7 +60,7 @@ class GptTranslate::Generator < Jekyll::Generator 
     | 
|
| 
       60 
60 
     | 
    
         
             
                copied = 0
         
     | 
| 
       61 
61 
     | 
    
         
             
                model = config['model'] || 'gpt-3.5-turbo'
         
     | 
| 
       62 
62 
     | 
    
         
             
                marker = "Translated by ChatGPT #{model}#{version.empty? ? '' : "/#{version}"}"
         
     | 
| 
       63 
     | 
    
         
            -
                site.posts.docs.shuffle. 
     | 
| 
      
 63 
     | 
    
         
            +
                site.posts.docs.shuffle.each_with_index do |doc, pos|
         
     | 
| 
       64 
64 
     | 
    
         
             
                  plain = GptTranslate::Plain.new(doc.content).to_s
         
     | 
| 
       65 
65 
     | 
    
         
             
                  config['targets'].each do |target|
         
     | 
| 
       66 
66 
     | 
    
         
             
                    start = Time.now
         
     | 
| 
         @@ -86,12 +86,14 @@ class GptTranslate::Generator < Jekyll::Generator 
     | 
|
| 
       86 
86 
     | 
    
         
             
                    )
         
     | 
| 
       87 
87 
     | 
    
         
             
                    html = config['no_download'].nil? ? GptTranslate::Ping.new(site, link).download : nil
         
     | 
| 
       88 
88 
     | 
    
         
             
                    needed = false
         
     | 
| 
      
 89 
     | 
    
         
            +
                    added = false
         
     | 
| 
       89 
90 
     | 
    
         
             
                    if html.nil?
         
     | 
| 
       90 
91 
     | 
    
         
             
                      Jekyll.logger.info("The page is absent, need to translate #{link.inspect}")
         
     | 
| 
       91 
92 
     | 
    
         
             
                      needed = true
         
     | 
| 
       92 
93 
     | 
    
         
             
                    else
         
     | 
| 
       93 
94 
     | 
    
         
             
                      copied += 1
         
     | 
| 
       94 
95 
     | 
    
         
             
                      site.static_files << DownloadedFile.new(site, link, html)
         
     | 
| 
      
 96 
     | 
    
         
            +
                      added = true
         
     | 
| 
       95 
97 
     | 
    
         
             
                      if version.empty?
         
     | 
| 
       96 
98 
     | 
    
         
             
                        Jekyll.logger.info("Re-translation not required, since version is empty: #{link.inspect}")
         
     | 
| 
       97 
99 
     | 
    
         
             
                      elsif html.include?(marker)
         
     | 
| 
         @@ -103,7 +105,7 @@ class GptTranslate::Generator < Jekyll::Generator 
     | 
|
| 
       103 
105 
     | 
    
         
             
                      end
         
     | 
| 
       104 
106 
     | 
    
         
             
                    end
         
     | 
| 
       105 
107 
     | 
    
         
             
                    if translated >= threshold
         
     | 
| 
       106 
     | 
    
         
            -
                      Jekyll.logger.info(" 
     | 
| 
      
 108 
     | 
    
         
            +
                      Jekyll.logger.info("Page ##{pos} is ignored, we are over the threshold of #{threshold}: #{link}")
         
     | 
| 
       107 
109 
     | 
    
         
             
                    elsif needed
         
     | 
| 
       108 
110 
     | 
    
         
             
                      gpt = GptTranslate::ChatGPT.new(
         
     | 
| 
       109 
111 
     | 
    
         
             
                        key,
         
     | 
| 
         @@ -124,10 +126,12 @@ class GptTranslate::Generator < Jekyll::Generator 
     | 
|
| 
       124 
126 
     | 
    
         
             
                      )
         
     | 
| 
       125 
127 
     | 
    
         
             
                      site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
         
     | 
| 
       126 
128 
     | 
    
         
             
                      site.static_files.delete_if { |f| f.is_a?(DownloadedFile) && f.link == link }
         
     | 
| 
      
 129 
     | 
    
         
            +
                      added = true
         
     | 
| 
       127 
130 
     | 
    
         
             
                      translated += 1
         
     | 
| 
       128 
131 
     | 
    
         
             
                      Jekyll.logger.info("Translated via ChatGPT \
         
     | 
| 
       129 
132 
     | 
    
         
             
            in #{(Time.now - start).round(2)}s: #{path} (#{File.size(path)} bytes)")
         
     | 
| 
       130 
133 
     | 
    
         
             
                    end
         
     | 
| 
      
 134 
     | 
    
         
            +
                    next unless added
         
     | 
| 
       131 
135 
     | 
    
         
             
                    doc.data['chatgpt-translate'] ||= {}
         
     | 
| 
       132 
136 
     | 
    
         
             
                    doc.data['chatgpt-translate']['model'] ||= model
         
     | 
| 
       133 
137 
     | 
    
         
             
                    doc.data['chatgpt-translate']['urls'] ||= {}
         
     | 
| 
         @@ -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
         
     | 
| 
         @@ -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_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.33
         
     | 
| 
       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-30 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: iri
         
     |