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

jo-i18n

v0.0.8

Published

A i18n library, you can use it set dictionary and format message base on the standard BCP 47 and ICU.

Downloads

6

Readme

jo-i18n

jo-i18n是基于messageformat之上构建的国际化解决方案,得益于messageformat的优良特性,jo-i18n支持Unicode CLDR标准中的所有语言,能够帮助你处理单复数日期性别等语言翻译问题。

ICU标准提供了关于单复数、日期、性别等格式化的官方指导,除了被遗弃的ChoiceFormatjo-i18n支持标准中的所有格式语法,同时jo-i18n提供了对语言标签(language tags)的检验,在BCP 47,保证了语言标签的准确合规。

jo-i18n能帮您解决什么问题?

通过jo-i18n,你可以做到业务代码和语言格式化(翻译)松耦合,也就是说,我们只需要对现有的代码进行极小的改动就能够是我们的应用变成国际化应用。

安装jo-i18n

npm install jo-i18n

简单的使用

<html>
  	<!--设置语言为en,如果没有设置,jo-i18n将从环境中读取当前所选语言-->
	<meta http-equiv="Content-Language" content="en">
</html>
// dist.js
const msg =
  '{GENDER, select, male{He} female{She} other{They} }' +
  ' found ' +
  '{RES, plural, =0{no results} one{1 result} other{# results} }' +
  ' in the ' +
  '{CAT, selectordinal, one{#st} two{#nd} few{#rd} other{#th} }' +
  ' category.';

export default const dist = {
  'en': {
    'TOTAL_ITEM': msg
  }
}

// index.js
import { extendDict, __ } from 'jo-i18n'
import dist from './dist'

extendDist(dist)

__('TOTAL_ITEM', { GENDER: 'male', RES: 1, CAT: 2 })
// 'He found 1 result in the 2nd category.'
__('TOTAL_ITEM', { GENDER: 'female', RES: 1, CAT: 2 }) 
// 'She found 1 result in the 2nd category.'
__('TOTAL_ITEM', { RES: 2, CAT: 2 }) 
// 'They found 2 results in the 2nd category.'

上面的简单实例展示了jo-i18n在处理性别、单复数和序数等问题的格式化。更多格式语法

结合其他框架

Angular

jo-i18n目前很好得支持Angular框架,项目提供了translateProvider方法为你轻松创建国际化翻译指令。

// translate.js
import angular from 'angular';
import { translateProvider } from 'jo-i18n';

export default translateProvider(angular, 'yourTranslate');
// index.js
import yourTranslate from './translate'
angular.module('App', [yourTranslate])

如上您就可以在你的模板中使用yourTranslate指令了。

<div your-translate>我住在上海<span notranslate>我不会被翻译</span></div>

注:需要把需要翻译的字段通过extendDict方法添加到字典表中。

extendDict({'en': {
  '我住在上海': 'I live in Shanghai'
}})

MIT License