i18n-webpack-plugin icon indicating copy to clipboard operation
i18n-webpack-plugin copied to clipboard

How to use this in html

Open knvpk opened this issue 9 years ago • 11 comments
trafficstars

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.

knvpk avatar Mar 04 '16 06:03 knvpk

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>';

joeheyming avatar May 12 '16 20:05 joeheyming

Oh, that's pretty awesome. Could this be documented?

ronkorving avatar May 16 '16 10:05 ronkorving

yes documentation would be amazing.

Jorybraun avatar Nov 28 '16 20:11 Jorybraun

How to use this in jade ? p= __("hello") ?

Teemo12345 avatar Jul 12 '17 09:07 Teemo12345

@Teemo12345 I want to know this too. Do you have any idea now?

BigLiao avatar Dec 18 '17 01:12 BigLiao

add &globals=__ to loader options OR pass __ to it

iliakan avatar Aug 31 '18 20:08 iliakan

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

PACMAN49 avatar Sep 13 '18 07:09 PACMAN49

That's from my config, modules section:

        {
          test: /\.pug$/,
          use:  'pug-loader?root=' + config.projectRoot + '/templates&globals=__'
        },

iliakan avatar Sep 13 '18 07:09 iliakan

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

PACMAN49 avatar Sep 13 '18 08:09 PACMAN49

The question I answered was about jade/pug, not html, sorry.

iliakan avatar Sep 14 '18 16:09 iliakan

How could we use this syntax inside an html attribute? i.e. <a href="${_("https://link-to-locale-specific-page.com")}">Link</a>

cjayyy avatar Apr 10 '19 13:04 cjayyy