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

i18fn

v2.0.4

Published

i18n in one func

Downloads

37

Readme

中文说明文档

Use

I don't like in some i18n file add different string, and in your code use a atlas. i18fn is zero config i18n package, juse in you code like this:

$ npm i --save i18fn
const i18fn = require('i18fn');
const hello = i18fn({ English: 'hello', Chinese: '你好' });
console.log(hello);

Use params

const i18fn = require('i18fn');
const personHello = i18fn(
    { English: '__person__, hello', Chinese: '__person__, 你好' },
    {
      person: { English: 'Mr.Ming', Chinese: '小明' },
    },
  );
console.log(personHello);
});

Auto Miss language tip

If HTML language is chinese, but your forget add chinese txt, like this:

const say = i18fn({ English: 'hello' });

// In production, i18fn use english to forget language
// And In Devloper, i18fn use add - [Miss i18fn: languageType] in english
if (process.env.NODE_ENV === 'production') {
  console.log(say); // hello
} else {
  console.log(say); // hello - [Miss i18fn: english]
}

Set now language

If we want to modify the current language with settings, we can manually modify the current language to override the browser's language recognition:

const i18fn = require('i18fn');

i18fn.setNowLanguage('Chinese');

Still love config? you can like this

Normally, a language is a configuration file, but when you need to add a new string, you need to open many language files one by one, often missing. We can write multiple languages in a file like this:

const { lang } = require('i18fn');
const languages = {
  done: lang({ English: 'done!', Chinese: '完成!' }),
  hello: lang({ English: 'hello', Chinese: '你好' }),
  please: params => lang({ English: '__open__, please.', Chinese: '请__open__.' }, params),
};

console.log(languages.done);
console.log(
  languages.please({
    open: { English: 'Open the box', Chinese: '打开盒子' },
  }),
);

Auto differentiate languages

  • English
  • Chinese
  • ChineseTraditional
  • Dutch
  • Korea
  • French
  • German
  • Japanese
  • Italian
  • Portuguese
  • Spanish
  • Swedish
  • Russian
  • Arabic
  • Vietnamese
  • Polish
  • Finnish
  • Afrikaans
  • Khmer
  • Thai
  • Turkish
  • Ukrainian
  • Zulu

Add other language

If you need add Magyar language, like this:

const i18fn = require('i18fn');

i18fn.addLanguage('hu-HU', 'Magyar');

// ok like default use:
const hello = i18fn({ English: 'hello', Magyar: 'helló' });
console.log(hello);

test

Install package jest:

$ yarn install && yarn test

You can check test in src/index.test.js

$ jest
 PASS  src/index.test.js
  ✓ test chinese (4ms)
  ✓ test english
  ✓ test english params (1ms)
  ✓ test english params, use object
  ✓ test config
  ✓ test config function (1ms)
  ✓ test error chinese
  ✓ test error english
  ✓ test error chinese prod
  ✓ test error english prod (1ms)
  ✓ test add other language

Test Suites: 1 passed, 1 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        1.257s
Ran all test suites.
✨  Done in 1.80s.

That's all, thank.

i18fn is MIT licensed.