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

Functions in RequireJS i18n files. #20

Closed
ggriffithsIDBS opened this issue Mar 19, 2018 · 3 comments
Closed

Functions in RequireJS i18n files. #20

ggriffithsIDBS opened this issue Mar 19, 2018 · 3 comments

Comments

@ggriffithsIDBS
Copy link
Contributor

ggriffithsIDBS commented Mar 19, 2018

Hello

This isn't so much an issue as a question/pondering for help.

Last year i asked this question in stack overflow:
image

I've finally been brought back onto this task of migrating a legacy RequireJS app over to Webpack.
All was working great and i've been using your great loader. However, at various points in our code, whether correct or not we have i18n files that have functions, example:

 refreshFailedTitle: function(name) {
                return 'Failed to run query for \'' + name + '\'';
            },

Because of how Webpack works with loaders at build time, this straight up doesnt work and all the functions get evaluated to strings.
I've been unable to determine if us doing this was actually a violation of what RequireJS intended for the i18n, the RequireJS docs are a little lacking.

I've been able to put in this really shameful hack to get the code working, obviously this is not a good idea at all parsing to and from a string/function.
image

Do you have any thoughts about a better way of solving this issue, i have a feeling the solution is a refactor to put the functions into the code instead.

I hope you might be able to help :)

Edit: slightly more sane way of doing this without running anything at run time:
image

@Georgegriff
Copy link

Georgegriff commented Mar 19, 2018

Upon reviewing the code further if should just be trivial to perform a toString() on functions when doing JSON.stringify(ret) as above in not sure the code init is even needed

@ggriffithsIDBS
Copy link
Contributor Author

Updated snippet attached, doing this serialize works for our code, where we have functions inside of our i18n files

@TooBug
Copy link
Collaborator

TooBug commented Mar 20, 2018

Great! Could you please give a Pull Request? I'll review it, and merge it if the method is proper and doesn't break the other parts.

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

3 participants