npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18n-jsnext

v0.3.0

Published

I18n for modern web (typescript based, react batteries included)

Downloads

1

Readme

I18n for modern web

Install

  • yarn add i18n-jsnext
  • npm install i18n-jsnext --save

Features

  • typescript based source files and convenient api
  • loading localization resources with namespaces support (splitting to multiple files)
  • react.js built-in components (react >=16.3 required)
  • messageformat templates support

Plugins

  • reactPostProcess() (variables interpolation for react.js components)
  • keepLocale() (remember locale in localStorage or cookies and restore after page reload)

Usage with React (optional)

  • I18nProvider, I18nConsumer (provide/consume i18n instance for whole app)
  • i18nInjector() decorator for providing this.props.i18n within components
  • I18nMessage (general use i18n.translate wrapper)
  • I18nNumber, I18nPrice, I18nPercents (format numbers)
  • I18nDate (format date/time)
  • I18nPlural (pluralize word form, supports only single locale, not included in common bundle index.js)

Example

For more details see in ./example folder

// i18n-init.ts
import { I18n } from "i18n-jsnext";
import { keepLocale, reactPostProcess } from "i18n-jsnext/plugins";

export const i18n = new I18n({
  loadPath: "/locales/{locale}.json",
  plugins: [
    keepLocale(),
    reactPostProcess(),
  ]
});
// components/app.tsx
import * as React from "react";
import { render } from "react-dom";
import { I18nProvider, I18nMessage } from "i18n-jsnext";
import { i18n } from "../i18n-init";

class App extends React.Component {
  static init = async () => {
    await i18n.init(); // loading resources
    render(<App/>, document.getElementById('app'))
  };

  render() {
    return (
      <I18nProvider i18n={i18n}>
        <I18nMessage message="App.greetings" params={{
          now: Date.now(),
          highlight: content => <b onClick={() => window.alert("gotcha!")}>{content}</b>
        }}/>
      </I18nProvider>
    )
  }
}

App.init();
# components/app.intl.yml
en:
  App:
    greetings: 
      Hello <highlight>world</highlight>! # param "highlight" parsed with react-postprocess plugin
      Today is {now, date, full} # param "now" parsed with messageformat package
---
ru:
  App:
    greetings: 
      Привет <highlight>мир</highlight>!
      Сегодня {now, date, full}

Server-side addons

Require additional installs:

npm install commander glob js-yaml lodash --save

  • built-in locales route for express.js
import express from "express"
import { localesRoute } from "i18n-jsnext/locales-route";

const app = express();

// provide localization json files in runtime from source files folder.
// url for consuming: "/locale/en.json?ns=dictionary", 
// where "?ns=" optional query param to instruct the route provide resources from specific namespace only 
app.use(
  localesRoute({
    routePath: "/locales/:locale.json",
    srcDir: "client", // used to search localization files
    outputDir: "build", // used to check and provide generated static files if they exists
  })
);
  • built-in script to gather all localization files from the project and make complete json for consuming in production

Add to package.json runnable script:

"scripts": {
  "locales-build": "node ./node_modules/i18n-jsnext/build-locales.js client build"
}

Where client and build directories relative to project root, same as used in localesRoute() above.

Running demo

  1. git clone [email protected]:ixrock/i18n-jsnext.git
  2. cd ./i18n-jsnext
  3. yarn or npm install (compilation might have errors with npm)
  4. yarn dev or npm run dev

By default dev server will be running at port 9000. If it's already taken in your system you can run the project
as LOCAL_SERVER_PORT=9001 yarn dev or change the port at ./example/server/config.ts and try again. `

Useful links:

Find plural categories for specific locale and their corresponding numeric rules:

  • http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html

Powered by typescript, react, webpack and some others. Made with ♥