How is js-translation.json file generated?

If you want just to use JavaScript translation read the topics:

Here is in deep internal explanation of how the JavaScript translation dictionary js-translation.json is generated.

Step 1

Client part of Magento 2 requests the js-translation.json file from the server part.

Step 2

The js-translation.json file is generated dynamically.
The server uses \Magento\Translation\Model\Json\PreProcessor class instance to handle the request:

Step 3

The \Magento\Translation\Model\Json\PreProcessor class instance parses the Knockout templates and JavaScript files to create a dictionary:

The parsing is implemented using regular expressions:

A more comprehensive analysis after 2 years:

See also: