Functions in RequireJS i18n files.
ggriffithsIDBS opened this issue · 3 comments
Hello
This isn't so much an issue as a question/pondering for help.
Last year i asked this question in stack overflow:
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.
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:
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
Updated snippet attached, doing this serialize works for our code, where we have functions inside of our i18n files
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.