LoginSignup
1
1

More than 3 years have passed since last update.

コメントアウトを翻訳するPythonモジュールを作ってみた

Posted at

はじめに

タイトルの通り、ソースファイルにあるコメントアウトを翻訳するモジュールを作ってみました。

使い方などはgithub、またはPyPiを見ていただければと思います。

https://github.com/koboriakira/translate-comment-out
https://pypi.org/project/translate-comment-out/

背景

Reactで使われているwebpack.config.jsのソースを読もうと思ったのですが、英文の説明を読むのが大変でした。

とりあえずザックリでいいから日本語訳を読んでおきたいなと思い、2時間ぐらいで作ってみました。

もとのwebpack.config.js

webpack.config.js
// This is the production and development configuration.
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
module.exports = function(webpackEnv) {
  const isEnvDevelopment = webpackEnv === 'development';
  const isEnvProduction = webpackEnv === 'production';

  // Variable used for enabling profiling in Production
  // passed into alias object. Uses a flag if passed into the build command
  const isEnvProductionProfile =
    isEnvProduction && process.argv.includes('--profile');

  // We will provide `paths.publicUrlOrPath` to our app
  // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
  // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
  // Get environment variables to inject into our app.
  const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));

翻訳後

tco webpack.config.js > webpack.config_ja.jsで出力したファイルです。

webpack.config_ja.js
// これは、本番および開発の構成です。これは、開発者の経験、高速な再構築、および最小
// 限のバンドルに重点を置いています。
module.exports = function(webpackEnv) {
  const isEnvDevelopment = webpackEnv === 'development';
  const isEnvProduction = webpackEnv === 'production';

  // エイリアスオブジェクトに渡される本番環境でプロファイリングを有効にするために使用
  // される変数。ビルドコマンドに渡された場合はフラグを使用します
  const isEnvProductionProfile =
    isEnvProduction && process.argv.includes('--profile');

  // アプリに `paths.publicUrlOrPath`をʻindex.html
  // `では%PUBLIC_URL%、JavaScriptでは` process.en
  // v.PUBLIC_URL`として提供します。 %PUBLIC_URL%/ xyz
  // は%PUBLIC_URL%xyzよりも見栄えがよいため、末尾のスラッシュは省略し
  // てください。アプリに挿入する環境変数を取得します。
  const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));

備考

上記の目的のため、JavaScriptの//によるコメントアウトにしか使えません。

仕組みは単純なので、他の言語でも試してみたい方はぜひforkして開発いただければと思います。

1
1
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
1
1