Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Bug: Concatenate strings in i18n #32

Open
Rincewind3d opened this issue Feb 8, 2017 · 1 comment
Open

Bug: Concatenate strings in i18n #32

Rincewind3d opened this issue Feb 8, 2017 · 1 comment

Comments

@Rincewind3d
Copy link

Hello,

this may be a basic problem/limitation from Webpack, but perhaps someone has an idea.

If i18n is called with a string concatenation Webpack throws an reference error.

let foo = 'foo';
__('bar.'+foo);
ReferenceError: __ is not defined

I checked the i18n-webpack-plugin code and figured out the the problem is this.evaluateExpression(expr.arguments[0]) which is not working if there's string concatenation. My knowledge about webpack plugins is limited, perhaps someone has an idea?

The use for this string concatenation is in combination with the html-webpack-plugin.
For each site I define a template variable with the name of the site and use it to get the translation for the header title.

<head>
  <title>${__('view.' + htmlWebpackPlugin.options.environment.viewName + '.title')}</title>
</head>

Yeah, es6 template would be better. But as in #6 described it's not working.

@sullenor
Copy link
Collaborator

sullenor commented Aug 4, 2017

Hi, the current version works only with the string literals as an argument as you found earlier and skips other combinations (binary expressions and e.t.c.). Thats why the function call __() remains untouched which results in exception.

I did a small modification in #58 which provides possibility to use string concatenation (BinaryExpressions) and templated strings (TemplateLiteral) with variables also. But it requires some time for review and to land into the master.

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

No branches or pull requests

4 participants