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

How to use this in html #15

Open
knvpk opened this issue Mar 4, 2016 · 11 comments
Open

How to use this in html #15

knvpk opened this issue Mar 4, 2016 · 11 comments

Comments

@knvpk
Copy link

knvpk commented Mar 4, 2016

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
Copy link

joeheyming commented May 12, 2016

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
Copy link

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

@Jorybraun
Copy link

yes documentation would be amazing.

@Teemo12345
Copy link

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

@BigLiao
Copy link

BigLiao commented Dec 18, 2017

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

@iliakan
Copy link

iliakan commented Aug 31, 2018

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

@PACMAN49
Copy link

PACMAN49 commented Sep 13, 2018

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
Copy link

iliakan commented Sep 13, 2018

That's from my config, modules section:

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

@PACMAN49
Copy link

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
Copy link

iliakan commented Sep 14, 2018

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

@cjayyy
Copy link

cjayyy commented Apr 10, 2019

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

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

10 participants