Skip to content

Instantly share code, notes, and snippets.

@kyktommy
Last active March 4, 2021 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyktommy/746e8c6a2e15b41dc947fb83cbd3b287 to your computer and use it in GitHub Desktop.
Save kyktommy/746e8c6a2e15b41dc947fb83cbd3b287 to your computer and use it in GitHub Desktop.
ejs + format str
const ejs = require("ejs");
const IntlMessageFormat = require("intl-messageformat").default;
const t = (str, obj) => new IntlMessageFormat(str).format(obj);
const data = { t: t, title: "hello world {name}" };
const html = ejs.render("<%- t(title, {name: 'bot'}) %>", data);
console.log(html);
const ejs = require("ejs");
const t = require("util").format;
const data = { t, title: "hello world %s" };
const html = ejs.render("<%- t(title, 'bot') %>", data);
console.log(html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment