Skip to content
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

Compiling messages during build #48

Open
glen-84 opened this issue Sep 19, 2019 · 4 comments
Open

Compiling messages during build #48

glen-84 opened this issue Sep 19, 2019 · 4 comments

Comments

@glen-84
Copy link

glen-84 commented Sep 19, 2019

The messageformat documentation recommends using messageformat as a compile-time tool, to avoid having to download the compiler to the client and compile messages at run-time. It also solves the CSP issue.

Is there any way to use pre-compiled messages with this library?

@lephyrus
Copy link
Owner

I don't think that's a use case for this library, to be honest. But I've had the same idea for some time, and I agree that it would be a better solution. I feel it should be a separate library. I've been wanting to take a crack at it, but I didn't get around to it so far.

@AndreasHae
Copy link

@lephyrus I managed to get it working by using a custom webpack config which sets up @messageformat/loader for my translation files and then writing a custom TranslateLoader which dynamically imports the translation JSON files. Works like a charm!

Not sure how to package this into a library though, as it requires a custom webpack config to work. Might write a tutorial about it when I have the time

@lephyrus
Copy link
Owner

@AndreasHae Good to hear that works! 👍 I always wanted to give it a try. The only option off the top of my head was using a custom webpack config too. That's not straight-forward to package, as you say. But more importantly, supplying a custom webpack config is a somewhat niche thing to do: I feel like conceptually, webpack is an implementation detail of the Angular CLI. There's already experimental support for Angular builds that don't use webpack at all.

Still, if you want to try to fork my StackBlitz example app and adapt it to use pre-compiled messages, I'll be happy to link it in the README. (StackBlitz lets you edit angular.json, so I think it should be possible.)

@jeandat
Copy link

jeandat commented Feb 12, 2024

@lephyrus I managed to get it working by using a custom webpack config which sets up @messageformat/loader for my translation files and then writing a custom TranslateLoader which dynamically imports the translation JSON files. Works like a charm!

Not sure how to package this into a library though, as it requires a custom webpack config to work. Might write a tutorial about it when I have the time

Hi @AndreasHae, did you write that tutorial by any chance? Could be useful to me too. Thanks. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants