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

tb-i18n

v0.1.0

Published

I18n for teambition web.

Downloads

2

Readme

tb-i18n

NPMversion A library to translate i18n key and value.

Usage

npm install tb-i18n --save-dev

API

i18n.getLanguage()

To get the current language of i18n. The Default language of i18n is 'en'.

let lang = i18n.getLanguage()
console.log(lang)

The result of log is 'en'.

i18n.setLanguage(language)

To change language of i18n.

i18n.setLanguage('zh')

i18n.getLocales(language)

To get the locales of specified language

let locales = i18n.getLocales('zh')

i18n.setLocales(language, locales)

To extend i18n locales of specified language

i18n.setLocales('en', {
  'key1': 'My name is suyu34.',
  'key2': 'I come from %s.'
})
let value = i18n.get('key1')

The result of value is 'My name is suyu34.'. So it is how i18n works.

i18n.get(key, args...)

To get default value of any key.

i18n.setLocales('en', {
  'key1': 'My name is suyu34.',
  'key2': 'I come from %s.',
  'key3': 'My name is %1 and come from %2.',
  'key4': 'My name is %s and come from %s.',
})

// transition: My name is suyu34.
// result:     My name is suyu34.
let value1 = i18n.get('key1')

// transition: I come from %s.
// result:     I come from CQ.
let value2 = i18n.get('key2', 'CQ')

// transition: My name is %1 and come from %2.
// result:     My name is suyu34 and come from CQ.
let value3 = i18n.get('key3', 'suyu34', 'CQ')

// transition: My name is %s and come from %s.
// result:     My name is suyu34 and come from CQ.
let value4 = i18n.get('key4', 'suyu34', 'CQ')

The values of key1, key2 and key3 are dynamic. They must have input values when get.So there has two ways to replace value:

  • Index Replace: Mark %1, %2... in transition and i18n will replace it by fixed order. It not care about the order of values, but index of values. The example of index replace is 'key3'.
  • Zero Replace: Mark %s, %s... in transition and i18n will replace by input values one by one. The order of values will influences the result. The example of zero replace is 'key4'.

i18n.point(key, language, args...)

To get transition of specified language. Like i18n.get but it accept a specified language.

i18n.setLocales('zh', {
  'key1': '我是suyu34。',
  'key2': '我来自%s。',
  'key3': '我是%1,来自%2。',
  'key4': '我是%s,来自%s。',
})

// transition: 我是suyu34。
// result:     我是suyu34。
let value1 = i18n.point('key1', 'zh')

// transition: 我来自%s。
// result:     我来自CQ。
let value2 = i18n.point('key2', 'zh', 'CQ')

// transition: 我是%1,来自%2。
// result:     我是suyu34,来自CQ。
let value3 = i18n.get('key3', 'zh', 'suyu34', 'CQ')

// transition: 我是%s,来自%s。
// result:     我是suyu34,来自CQ。
let value4 = i18n.get('key4', 'zh', 'suyu34', 'CQ')

License

MIT