-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The correct way to extract translations from Twig #1
Comments
Hello The purpose of this bundle is to extract translations from js file using bazinga js bundle syntax. Is there any reason you don't use the |
Sometimes I prefer/need to add some JS code directly inside twig block with some params for example: file.rejectDimensions = function () {
done(Translator.trans('dropzone_min_width_restriction', {'minImageWidth': that.options.minImageWidth}, 'admin_js'));
}; I can't use |
Ok, it's a good reason ! |
Sorry for delay, I haven't look really yet, but given classes are final, I don't see a better way for now. can you share a bit more your code so I can integrate this use case in this bundle ? |
My use case
accept: function (file, done) {
let that = this;
{% if user.dimensionRestriction %}
file.rejectDimensions = function () {
done(Translator.trans('dropzone_min_width_restriction', {'minImageWidth': that.options.minImageWidth}, 'admin_js'));
};
file.acceptDimensions = done;
{% endif %}
}, There is a little bit more logic in accept and init functions which are generated in twig and parameters like fileSize are taken to messages from Dropzone options. Of course I could rewrite that code and put everything into some generic js method, put my dynamic params into html data and then read them from that generic method. I think it's a rare case, but I was wonder if your bundle can handle it. All in all I made some hack, so it's generally working fine. If you want to keep your classes final the only thing I came up with is it to make |
Hey ! As you may have understood, I didn't do any changes to integrate your use case. Sorry for that. With arrival of PHP8, a contributor has added today the support of PHP8 on others libs related to this one js-translation-extractor and php-translation-js-extractor-bundle. I plan to add PHP8 support on this lib as well but it needs to remove PHP 5.x / 7.0 / 7.1 support. (#2) If you tell me no, I would probably add your use case only in the next upcoming version covering PHP ≥ 7.2 Please let me know your needs, so I can try to adapt update strategy to the simplest needed one ;) |
Thanks for clarification. I think that my case is quite rare so I do not think that resolving it is worth your work. What's more there are some solutions to write a few good workarounds. For me we can close this issue. |
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
I tried to extend your class to only override
visitTwigFile
method, but I'm not able to extendfinal
class.Finally I created a following constructor:
and "extended" your methods like that
However it's not the best option. How it should be done?
The text was updated successfully, but these errors were encountered: