globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 603 forks source link

Does Globalize.formatMessage() support passing a variable as path parameter? #707

Open xtingx opened 7 years ago

xtingx commented 7 years ago

The following code works well. const Globalize = require('globalize'); Globalize.formatMessage('my.path');

But the following code did not work. That is to say Globalize.formatMessage() only access a string as parameter,if passing a variable as parameter, it doesn't work. I got error "ReferenceError: path is not defined" Is it the design? if yes, how can I pass a variable to Globalize.formatMessage()? const Globalize = require('globalize'); const path = 'my.path'; Globalize.formatMessage(path);

aarshaw commented 7 years ago

Any luck with this? Having the same issue.

gear3g commented 5 years ago

I'm facing the same issue. It happend during build. I'm using globalize-webpack to build.

Please take a look on below log.

\node_modules\globalize-webpack-plugin\GlobalizeCompilerHelper.js:77
        throw e;
        ^

ReferenceError: variable is not defined
    at eval (eval at extractor (\node_modules\globalize-compiler\lib\extract.js:65:9), <anonymous>:16:3)
    at \node_modules\globalize-compiler\lib\compile-extracts.js:70:23
    at Array.reduce (<anonymous>)
    at Object.compileExtracts (\node_modules\globalize-compiler\lib\compile-extracts.js:69:49)
    at GlobalizeCompilerHelper.compile (\node_modules\globalize-webpack-plugin\GlobalizeCompilerHelper.js:68:35)
    at chunk.mapModules (\node_modules\globalize-webpack-plugin\ProductionModePlugin.js:251:53)
    at Function.from (native)
    at Chunk.mapModules (\node_modules\webpack\lib\Chunk.js:163:16)
    at compilation.chunks.filter.forEach (\node_modules\globalize-webpack-plugin\ProductionModePlugin.js:246:38)
    at Array.forEach (<anonymous>)
    at Compilation.compilation.plugin (\node_modules\globalize-webpack-plugin\ProductionModePlugin.js:232:12)
    at Compilation.applyPlugins1 (\node_modules\tapable\lib\Tapable.js:75:14)
    at sealPart2 (\node_modules\webpack\lib\Compilation.js:626:9)
    at next (\node_modules\tapable\lib\Tapable.js:202:11)
    at \node_modules\extract-text-webpack-plugin\dist\index.js:244:13
    at \node_modules\async\dist\async.js:473:16