PHPackages                             coffreo/php-translation-js-extractor-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. coffreo/php-translation-js-extractor-bundle

ActiveSymfony-bundle[Localization &amp; i18n](/categories/localization)

coffreo/php-translation-js-extractor-bundle
===========================================

Add javascript translation extractor for php-translation/symfony-bundle package

v2.1.2(1y ago)135.3k—1.8%6[2 PRs](https://github.com/Coffreo/php-translation-js-extractor-bundle/pulls)MITPHPPHP ^7.2 || ^8.0

Since Apr 25Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Coffreo/php-translation-js-extractor-bundle)[ Packagist](https://packagist.org/packages/coffreo/php-translation-js-extractor-bundle)[ RSS](/packages/coffreo-php-translation-js-extractor-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (10)Used By (0)

Coffreo/php-translation-js-extractor
====================================

[](#coffreophp-translation-js-extractor)

By [Coffreo](https://coffreo.biz)

[![PHP from Packagist](https://camo.githubusercontent.com/8e8d40e39f494c22d7462a987e5bd707c86bca47b83c391df77311ba5c8c1d5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f666672656f2f7068702d7472616e736c6174696f6e2d6a732d657874726163746f722d62756e646c652e737667)](https://camo.githubusercontent.com/8e8d40e39f494c22d7462a987e5bd707c86bca47b83c391df77311ba5c8c1d5c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f666672656f2f7068702d7472616e736c6174696f6e2d6a732d657874726163746f722d62756e646c652e737667)[![Build Status](https://camo.githubusercontent.com/24915ad380788383c00cf7c1aae502635b728f0b2c8601a10c19d3047ddb6ef6/68747470733a2f2f7472617669732d63692e6f72672f436f666672656f2f7068702d7472616e736c6174696f6e2d6a732d657874726163746f722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Coffreo/php-translation-js-extractor-bundle)[![Coverage](https://camo.githubusercontent.com/51dd85f015fdf4f96de9712ce958135cc904049fbe7b00c0dc39c4fc76e7a267/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f636f666672656f2f7068702d7472616e736c6174696f6e2d6a732d657874726163746f722d62756e646c652e737667)](https://scrutinizer-ci.com/g/coffreo/php-translation-js-extractor-bundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3f541ddcdf8d5071c1822662d4adbf30846b6e558145c99528f582a7b21d3307/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f666672656f2f7068702d7472616e736c6174696f6e2d6a732d657874726163746f722d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Coffreo/php-translation-js-extractor-bundle/?branch=master)

Extract translations from Javascript source files.

- **Recommended** [`willdurand/js-translation-bundle`](https://github.com/willdurand/BazingaJsTranslationBundle)

> Same bundle exists for [JMSTranslation](http://jmsyst.com/bundles/JMSTranslationBundle): see [Coffreo/jms-translation-js-extractor-bundle](https://github.com/Coffreo/jms-translation-js-extractor-bundle)

Installation
------------

[](#installation)

### Application with Symfony flex

[](#application-with-symfony-flex)

```
composer require coffreo/php-translation-js-extractor-bundle

```

### Application without Symfony flex

[](#application-without-symfony-flex)

- Install bundle

    ```
    composer require coffreo/php-translation-js-extractor-bundle

    ```
- Enable bundle:

    - symfony 3.\*

        ```
        // config/AppKernel.php
        public function registerBundles()
        {
            return array(
                // ...
                new Coffreo\PHPTranslationJsExtractorBundle\CoffreoPHPTranslationJsExtractorBundle(),
                // ...
            );
        }
        ```
    - symfony 4.\* (if not already added by `symfony/flex`)

        ```
        // config/bundles.php

        return [
            // ...
            Coffreo\PHPTranslationJsExtractorBundle\CoffreoPHPTranslationJsExtractorBundle::class => ['all' => true],
        ];
        ```

Usage
-----

[](#usage)

This bundle allow extraction of translated strings in javascript files using [Coffreo/js-translation-extractor](https://github.com/Coffreo/js-translation-extractor).

No specific command line to use, just use originals `php-translation/symfony-bundle` commands:

```
$ bin/console translation:extract ....
```

Translations found are automatically added to current translations files as PHP, twig ones.

### Configuration

[](#configuration)

This bundle doesn't need configuration.
However, to extract strings from JS files, you must indicate where are stored your JS files in [`php-translation/symfony-bundle` configuration](https://php-translation.readthedocs.io/en/latest/symfony/index.html#configuration).

```
# paths below are symfony 4.X paths, make sure to change them for sumfony 3.X
# config/packages/php_translation.yaml
translation:
    ...
    configs:
        app:
            dirs:
              - "%kernel.project_dir%/templates"
              - "%kernel.project_dir%/src"
              - "%kernel.project_dir%/assets"     #
