Giter VIP home page Giter VIP logo

jms-translation-js-extractor-bundle's People

Contributors

emri99 avatar

Watchers

 avatar  avatar  avatar

jms-translation-js-extractor-bundle's Issues

The correct way to extract translations from Twig

I tried to decorate service Coffreo\JMSTranslationJsExtractorBundle\Extractor\JsFileExtractor but Symfony gives me information that not such service exists.
Then I overrided service declaration in config to point out my custom service

coffreo.jms_translation.js_extractor.js:
        class:  App\Service\Decorators\JsFileExtractor  <---- my class
        arguments:
            - '@jms_translation.file_source_factory'
            - ['js', 'jsx']
        tags:
            - { name: 'jms_translation.file_visitor' }

I tried to extend your class to only override visitTwigFile method, but I'm not able to extend final class.

Finally I created a following constructor:

public function __construct(FileSourceFactory $fileSourceFactory, $extensions = null, JsTranslationExtractorInterface $extractor = null)
    {
        $this->fileSourceFactory = $fileSourceFactory;
        $this->jsFileExtractor = new \Coffreo\JMSTranslationJsExtractorBundle\Extractor\JsFileExtractor($fileSourceFactory, $extensions, $extractor);
    }

and "extended" your methods like that

public function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
    {
        $this->jsFileExtractor->visitFile($file, $catalogue);
    }

   public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, Node $ast)
    {
        $translations = $this->jsFileExtractor->findTranslations($file);

        foreach ($translations as $translation) {
            /** @var $translation TranslationString */
            $message = new Message($translation->getMessage(), $translation->getContext('domain') ?: 'messages');
            $message->setDesc($translation->getContext('desc'));
            $message->setDesc($translation->getContext('meaning'));
            $message->addSource($this->fileSourceFactory->create($file, $translation->getLine()));
            $catalogue->add($message);
        }
        $this->jsFileExtractor->visitTwigFile($file, $catalogue, $ast);

    }

However it's not the best option. How it should be done?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.