PHP code example of coffreo / js-translation-extractor

1. Go to this page and download the library: Download coffreo/js-translation-extractor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coffreo / js-translation-extractor example snippets


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();  // []