I made a Python module to translate comment outs

Introduction

As the title suggests, I made a module that translates comment outs in the source file.

Please see github or PyPi for how to use it.

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

background

I wanted to read the source of webpack.config.js used in React, but it was difficult to read the explanation in English.

For the time being, I wanted to read the Japanese translation because it's okay, so I made it in about 2 hours.

Example

Original 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));

After translation

This is the file output by tco webpack.config.js> webpack.config_ja.js.

webpack.config_ja.js


//This is a production and development configuration. This is developer experience, fast rebuilding, and minimal
//Focuses on limited bundles.
module.exports = function(webpackEnv) {
  const isEnvDevelopment = webpackEnv === 'development';
  const isEnvProduction = webpackEnv === 'production';

  //Used to enable profiling in the production environment passed to the alias object
  //Variables to be. Use flags if passed to build command
  const isEnvProductionProfile =
    isEnvProduction && process.argv.includes('--profile');

  //In the app`paths.publicUrlOrPath`ʻIndex.html
  // `Then% PUBLIC_URL%, in JavaScript` process.en
  // v.PUBLIC_URL`Provided as. % PUBLIC_URL%/ xyz
  //Is% PUBLIC_Omit the trailing slash because it looks better than URL% xyz
  //please. Gets the environment variables to insert into the app.
  const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));

Remarks

For the above purposes, it can only be used for commenting out with JavaScript //.

The mechanism is simple, so if you want to try it in other languages, please fork and develop it.

Recommended Posts

I made a Python module to translate comment outs
I made a python text
I made a python library to do rolling rank
I made a module in C language to filter images loaded by Python
I made a Line-bot using Python!
I made a fortune with Python.
I made a daemon with Python
I made a package to filter time series with python
I made a command to generate a table comment in Django
I made a library to easily read config files with Python
I made Othello to teach Python3 to children (4)
I made a payroll program in Python!
I made a character counter with Python
I made Othello to teach Python3 to children (2)
I want to build a Python environment
I made Othello to teach Python3 to children (5)
I made a script to display emoji
I made a Hex map with Python
I made a library that adds docstring to a Python stub file.
After studying Python3, I made a Slackbot
I made a roguelike game with Python
I made Othello to teach Python3 to children (3)
I made Othello to teach Python3 to children (1)
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
[Python] I made a decorator that doesn't seem to have any use.
I made a web application in Python that converts Markdown to HTML
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a script in python to convert .md files to Scrapbox format
I made a program to check the size of a file in Python
I made a function to see the movement of a two-dimensional array (Python)
I made a module PyNanaco that can charge nanaco credit with python
I made a python dictionary file for Neocomplete
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I want to create a window in Python
I made a Twitter fujoshi blocker with Python ①
I want to make a game with Python
[Python] I made a Youtube Downloader with Tkinter.
How to add a Python module search path
I made a tool to compile Hy natively
To add a module to python put in Julialang
I tried adding a Python3 module in C
I made a tool to get new articles
I want to write to a file with Python
I made a Caesar cryptographic program in Python.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Python Qiita API wrapper "qiipy"
〇✕ I made a game
Create a Python module
I made a Line Bot that uses Python to retrieve unread Gmail emails!
I made a script to record the active window using win32gui of Python
A story that I was addicted to when I made SFTP communication with python
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I made a prime number generation program in Python
Try to make a Python module in C language
I want to generate a UUID quickly (memorandum) ~ Python ~