yegor256 / jekyll-chatgpt-translate

Automated translating of Jekyll pages via ChatGPT: all you need is just an OpenAI API key
https://rubygems.org/gems/jekyll-chatgpt-translate
MIT License
15 stars 1 forks source link
chatgpt chatgpt-app internationalization jekyll jekyll-plugin translation

Translator of Jekyll Pages via ChatGPT

logo

rake Gem Version

If you have a Jekyll static site, this plugin may help you automatically translate its pages to another language, through ChatGPT. See how it works for my blog, for example this page is translated to English.

Install it first (you need Ruby 3+ and Jekyll 3+):

gem install jekyll-chatgpt-translate

Then, add this to _config.yml:

plugins:
  - ... your other plugins here ...
  - jekyll-chatgpt-translate
chatgpt-translate:
  model: gpt-3.5-turbo
  source: en
  layout: translated
  targets: 
    - 
      language: zh
      permalink: :year-:month-:day-:slug-chinese.html
      layout: chinese-translated
    - 
      only: ru-post
      language: fr
      permalink: :year-:month-:day-:title-french.html

Here, the source language is English (en), the targets are Chinese (zh) and French (fr), where the layout for Chinese is _layout/chinese-translated.html and for French is _layout/translated.html (you must have these files).

OpenAI API KEY must be set in the OPENAI_API_KEY environment variable, otherwise the plugin will not do any translation and won't generate translated pages. You can get your key here.

OpenAI API base URL can be customized by the OPENAI_API_BASE environment variable. If this variable is not set, the default value is https://api.openai.com/.

Inside the original page you can use {{ page.chatgpt-translate.urls[XX] }} in order to render the URL of the translated page, where XX is the ISO-639-1 code of the target language. Inside the translated page you can use {{ page.chatgpt-translate.original-url }} in order to get the URL of the page that was translated.

You can also use {{ page.chatgpt-translate.model }} inside both the original page and the translated one, to refer to the model of ChatGPT. The presence of {{ page.chatgpt-translate }} means that the page was translated or the translated HTML was downloaded and placed into the _site directory.

Options

Full list of options available to specify in _config.yml:

How to Contribute

Make a fork and then test it locally like this:

bundle update
bundle exec rake

If it works, make changes, test again, and then submit a pull request.

In order to run a single test, do this:

bundle exec ruby test/test_generator.rb