By Coffreo
Javascript translations extractor for willdurand/js-translation-bundle
This 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.
- extracts following strings from javascript files like a pro
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
- allow string delimiters to be
"
or'
- extracts multi-lines commands
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.
- Clone repository
- Execute
make [install] # to init composer after install
make test # to run test
- Find a way to add and extract desc/meaning values
This project is licensed under the MIT License - see the LICENSE file for details