Open knvpk opened 8 years ago
If your html-loader has the interpolate query parameter:
{ test: /.html$/, loader: 'html?interpolate' },
Then you can write this:
<div>${_("hello_world_key")}</div>
Which will compile to
module.exports = '<div>' + 'Hello world' + '</div>';
Oh, that's pretty awesome. Could this be documented?
yes documentation would be amazing.
How to use this in jade ? p= __("hello") ?
@Teemo12345 I want to know this too. Do you have any idea now?
add &globals=__
to loader options OR pass __ to it
add
&globals=__
to i18n options OR pass __ to it
can you provide an example of where to put this ? because can't figure out how to do it
That's from my config, modules section:
{
test: /\.pug$/,
use: 'pug-loader?root=' + config.projectRoot + '/templates&globals=__'
},
i m using html template
with this loader config
{ test: /\.html$/i, use: { loader: 'html-loader', options: { interpolate: true } } },
inside my html template i got
<labe>${_("Hello world")}</label>
but when i m executing it i got this JS error on loading
periodic.html:1 Uncaught ReferenceError: _ is not defined at eval (periodic.html:1) at
as i m not using pug i don't know how to apply your comment to my situation
The question I answered was about jade/pug, not html, sorry.
How could we use this syntax inside an html attribute?
i.e.
<a href="${_("https://link-to-locale-specific-page.com")}">Link</a>
in the examples it is shown that it can be used in javascript like
console.log(__("hello_world_key"))
but how do we use this in the .html pages.