webpack-contrib / i18n-webpack-plugin

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

How to use this in html #15

Open knvpk opened 8 years ago

knvpk commented 8 years ago

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.

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

ronkorving commented 8 years ago

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

Jorybraun commented 7 years ago

yes documentation would be amazing.

Teemo12345 commented 7 years ago

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

BigLiao commented 6 years ago

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

iliakan commented 6 years ago

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

PACMAN49 commented 6 years ago

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

iliakan commented 6 years ago

That's from my config, modules section:

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

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

iliakan commented 6 years ago

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

cjayyy commented 5 years ago

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