LoginSignup
0
0

More than 3 years have passed since last update.

I created a Python script that automatically translates my Qiita articles and posts them to Qiita / gist / Twitter

Posted at

This article is an automatic translation of the article[f1c47ab15c17d873fd03] below.
https://qiita.com/speaktech/items/f1c47ab15c17d873fd03

transQiita (made)

transQiita is a command line application using Qiita API v2 and googletrans. ** You can automatically translate articles on Qiita into English and post them to Qiita interactively (or non-interactively) by executing from the command line.
Also, you can post to gist/Twitter at the same time by using Qiita's GitHub linkage and Twitter linkage (optional).

** GitHub repository: ** tm-tech/transQiita

A quick demo!

transQiita-demo.gif

** Original article: **
https://qiita.com/speaktech/items/fa9dd70024865bff90f0

** English translation articles posted automatically by script: **
https://qiita.com/speaktech/items/99d1530950987019e7d4

Things necessary

-googletrans (It seems that there is a bug causing malfunction as of 9/20, this article)
-Qiita's access token (registered as environment variable QIITA_ACCESS_TOKEN, or specified directly as an option)

e.g.
$ pip install googletrans
$ export QIITA_ACCESS_TOKEN='YOUR QIITA ACCESS TOKEN'

Example command line

$ python transQiita.py  [-h] [--gist] [--tweet] [--private] [--auto] [--token TOKEN]

Optional arguments

-h, --help     ヘルプ
--gist         GitHub 連携していれば、gist へコードブロック部を投稿
--tweet        Twitter 連携していれば、投稿を Tweet
--private      記事を限定共有投稿
--auto         インタラクティブな実行をせず、自動実行(スケジュール実行時に利用)
--token TOKEN  環境変数を利用しない場合、Qiita のアクセストークンを指定

Limitations

  1. ** Code block part will not be translated, as indentation will be broken if code block part is translated. **
  2. ** Since the translation process inserts a space between the symbol and the character, markdown decoration such as"*"or"~ ~"does not work. *

Articles used for reference

-I wrote a Python script that exports all my posts using Qiita API v2
-A module that can use Google translation with python
-A template for creating command line applications in Python

Afterword

-*"Banner with original article ID"is added to the English translation as a mark so that update processing can be performed without using a database *.
When the original article is updated, the English translation article with the banner of the original article ID is found and updated.
You may manage the relationship between the original article and the English translation article in the database, but because I thought that preparing the database for that purpose would not be versatile, I aimed at a database-less design to make the code somewhat redundant. The
(Since it was assumed to be used in regular batch processing, it did not matter if the processing would be somewhat heavy.)

-** I tried to fix it with a regular expression for a fatal restriction ** where the markdown collapses, but""is translated to""and the irregular decoration symbol appears Because, I was frustrated. (Thinking solutions)

-Last but not the least
** This is the first Python post for me at the infrastructure store. I think that there are many places where debugging is insufficient, so it would be appreciated if you could report any problems! ** (little voice)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0