coffreo/js-translation-extractor
Extracts Laravel translation strings used in JavaScript by scanning your frontend source. Helps keep locale files in sync with JS usage and reduces missing-key issues in mixed Blade/Vue/React apps.
By Coffreo
willdurand/js-translation-bundleThis package is a small project existing to store in one place wonderfuls regexps to properly export translations
strings & metas from javascript source files.
It can be used standalone, but it's main goal is to be used in :
You only need to install this package manually for standalone usage and to integrate in your own translation extractor system:
composer require coffreo/js-translation-extractor
Using with Symfony JMSTranslationBundle
see coffreo/jms-translation-js-extractor-bundle installation guide.
Using with Symfony PHP Translation
see coffreo/php-translation-js-extractor-bundle installation guide.
trans('MESSAGE', {param: 'foo'}, 'DOMAIN')
// ^ 1st parameter is translation message
// ^ 3rd parameter is translation domain
transChoice('MESSAGE_WITH_PLURALS', 3, {param: 'foo'}, 'DOMAIN')
// ^ 1st parameter is translation message
// ^ 4th parameter is translation domain
// others parameters aren't extracted because they are useless.
Note that this is the syntax used by js-translation-bundle
" or 'use Coffreo\JsTranslationExtractor\Extractor\JsTranslationExtractor;
use Coffreo\JsTranslationExtractor\Model\TranslationCollection;
$extractor = new JsTranslationExtractor();
$translationCollection = new TranslationCollection();
$extractor->extract(<<<FILECONTENT
import Translator from 'bazinga-translator';
export default () => Translator.trans('This is awesome', {}, 'foo');
export {
bad: () => Translator.trans('This is ugly');
};
FILECONTENT
, $translationCollection);
$first = $translationCollection->first();
$first->getMessage(); // This is awesome
$first->getLine(); // 3
$first->getContext(); // ['domain' => 'foo']
$second = $translationCollection->get(1);
$second->getMessage(); // This is ugly
$second->getLine(); // 5
$second->getContext(); // []
Please fill an issue with informations to reproduce bug.
If your translated strings are not extracted properly, please provide a sample failing string.
make [install] # to init composer after install
make test # to run test
This project is licensed under the MIT License - see the LICENSE file for details
How can I help you explore Laravel packages today?