intl-hmessage
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

intl-hmessage

A Javascript international Tools

Install

npm install intl-hmessage
or
yarn add intl-hmeesage

LICENSE

MIT

Usage

The hmessage is base on intl-messageformat

Normal:

import { Lang, Message, DefaultPlugin } from "intl-hmessage";

Lang.use(DefaultPlugin);

const lang = new Lang("en");

const intl = new Message(
  {
    metas: {
      en: {
        t1: "test",
      },
      zh: {
        t1: "测试",
      },
    },
  },
  lang
);

console.log(intl.get("t1"));
// when your browser language is en: test.

getHtml:
If you using react or preact, you can use getHtml to genernate v-node.

import { Lang, Message, DefaultPlugin } from "intl-hmessage";

Lang.use(DefaultPlugin);

const lang = new Lang("en");

const intl = new Message(
  {
    metas: {
      en: {
        t1: "<p>test</p>",
      },
      zh: {
        t1: "<p>测试</p>",
      },
    },
  },
  lang,
  React.createElement // pass it!!!
);

function App() {
  return <>{intl.getHtml("t1")}</>;
}
// it displays test in html with p tag;

Note: you can use the lib with style-i18n-loader

Readme

Keywords

Package Sidebar

Install

npm i intl-hmessage

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

9.58 kB

Total Files

10

Last publish

Collaborators

  • mnishoward