-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add support for translation extraction from VueJs templates #178
Conversation
Checking the tests... |
JsFunctionsScanner now normalizes newline characters.
Will try to fix this on a linux machine. Tests on mac seem fine, but somehow CI converts something differently. |
@oscarotero Everything looks fine, can you consider merging this, please? :) |
src/Utils/VueJsFunctionScanner.php
Outdated
|
||
return $functions; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class is not necessary, the lineOffset could be added as an option for the JsFunctionScanner, so it can be reused by other javascript extractors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I'll make the changes after my vacation (14th of May). Hope this can sit here until then.
Hi. Sorry for the delay. <template>
{{ __('Hello world') }}
<p :attribute="__('One text')">Paragraph content {{ __('text') }}</p>
</template>
<script>
console.log(__('Other text'));
</script> would be converted to this: __('Hello world')
__('One text') __('text')
console.log(__('Other text')); Then, just use the jsCodeExtractor and that's it. So it could be reused by other future extractors like angular, react, etc. Anyway, if you need this now, I can merge it (after the requested change is made) and we can improve this in future versions. |
I'm not sure about the manual parsing of the template part, sounds like a lot of work and a lot of opportunities to mess things up if there's a mistake in the symbol counter. Especially for attributes where quotes can be escaped etc. Are you worried about the performance? |
It's not about performance, I think it's simpler than creating three fake javascripts, fixing line number issues, etc. All that things looks a bit hacky to me. Manual parsing is what is used in JsFunctionScanner and works great. In html I guess just controlling the open/close tags, open/close attributes, html comments and open/close {{expressions}} should be enought. That also prevents issues with invalid html. I dont think it's a lot of work (or maybe yes, you never know before start) 😄 |
Without DOM parsing, I imagine extracting attributes would be hard taking in account all quotes, escaping |
Ok, if the current implementation works fine, I'll merge it once the requesting change is made. |
…option (lineOffset)
VueJsFunctionScanner removed. |
Thanks! |
How it works - VueJs tempaltes basically are valid HTML. We extract template part (then extract dynamic attributes which are JS expressions and extract expressions from within template elements) and script part and parse them both as a regular JS.