webpack-contrib / i18n-webpack-plugin

[DEPRECATED] Embed localization into your bundle
MIT License
318 stars 74 forks source link

Does the i18n function need to be global? #18

Closed briandipalma closed 8 years ago

briandipalma commented 8 years ago

It looks like this plugin will only work if the i18n function is a global function. We are moving over a number of applications with large code bases to webpack and the way the applications currently implement i18n is like so:

var i18n = require('br/I18n');

...
            filterText = i18n('ct.grid.refine.refinersummary.filter.range', {
                fromValue: fromText,
                toValue: toText
            });
...

and in our en.properties file we have

ct.grid.refine.refinersummary.filter.range=[fromValue] - [toValue]

As i18n is bound from a require I can't use the webpack i18n plugin, that's all well and good but I'm curious how others actually use the global approach, I guess in your app entry point you export __() (or whichever function you configure webpack to use) to window so you don't trigger reference errors? Presumably the function that people export can do interpolation if they so require? Would it not make sense for this plugin to provide such a function, instead of having many similar copies in all the webpack projects?

briandipalma commented 8 years ago

Ah for crying out loud, you just replace the function, sorry for the questions. So this means that webpack i18n plugin functionality is limited to static strings...I guess if there was template string support then you could have interpolation support...OK well the way it currently works doesn't support our full set of use cases even with module local function support. It would also have to leave the function alone. I'll close this anyway as I'm not sure our use cases are something that you'd want to support. I guess most people deal with static translation text.