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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jimi-i18n

v1.0.2

Published

jimi-i18n

Readme

jimi-i18n

智能通讯部前端国际化解决方案

国际化语料资源文件的后缀为.properties,与Java的资源文件类似,文件的内容由key-value的形式组成。

jimi-i18n库根据用户指定的或者浏览器提供的语言和国家编码来解析对应的以.properties文件为后缀的资源文件。

jimi-i18n库首先加载默认的资源文件,然后加载针对特定语言环境的资源文件,这就保证了在未提供某种语言的翻译时,默认值始终有效。来发人员可以使用变量或Map的方式使用资源文件中的key

jimi-i18n有一下几个特点

  1. 使用Java标准的.properties文件作为资源文件,资源文件的命名有以下三种方式

    • basename.properties
    • basename_language.properties
    • basename_language_country.properties
  2. 使用ISO-639作为语言的编码标准,ISO-3166作为国家名称编码的标准

  3. 按顺序加载默认资源文件和指定语言环境的资源文件,保证默认值始终可用

  4. 在未指定语言环境时使用浏览器提供的语言

  5. 可以在资源字符串中使用占位符(例如: hello=你好{0}!今天是{1})

  6. 资源文件中的Key支持命名空间(例如:com.company.msg.hello = Hello)

  7. 支持跨行的值

  8. 可以以Javascript变量或Map的方式使用资源文件中的Key

API

|方法名|参数|描述| |----|----|----| |install(cfg)|Object|传入配置参数使国际化资源文件生效| |prop(key,[v1, v2])|String, Array|获取key在当前语言环境下的value, v1,v2为占位符中的值,若没有定义占位符,则不传|

配置说明

|选项|类型|描述|是否可选| |----|----|----|----| |name|String|资源文件的名称,例如strings或[string1, string2],前者代表一个资源文件,后者代表资源文件数组|否| |path|String|资源文件所在目录的路径|否| |mode|String|加载模式:“vars”表示以 JavaScript 变量或函数的形式使用资源文件中的 Key,“map”表示以 Map 的方式使用资源文件中的 Key,“both”表示可以同时使用两种方式。如果资源文件中的 Key 包含 JavaScript 的关键字,则只能采用“map”。默认值是“vars”。|是| |language|String|ISO-639 指定的语言编码(如:“en”表示英文、“zh”表示中文),或同时使用 ISO-639 指定的语言编码和 ISO-3166 指定的国家编码(如:“en_US”,“zh_CN”等)。如果不指定,则采用浏览器报告的语言编码。|是| |encoding|String|加载资源文件时使用的编码。默认为 UTF-8。|是| |callback|function|代码执行完成时运行的回调函数|是|

安装

// npm方式
$ npm install jimi-i18n --save

// <script>标签直接引入
<script src="./jimi-i18n/jimi-i18n.js"></script>

Useage

1. 创建资源文件

/i81n/
   |__ test.properties
   |__ test_en.properties
   |__ test_zh.properties
   |__ test_zh_CN.properties
// test.properties文件
test_username = 用户名
test_password = 密码


// test_en.properties文件
test_username = UserName
test_password = Password

2. 加载及使用

// 引入组件
var I18n = require('jimi-i18n');
// 获取实例
var i18n = I18n.getInstance();
// 调用install 方法让国际化生效
i18n.install({
    name: 'test',
    path: '/i18n/',
    mode: 'both',
    callback: function() {
        console.log('资源文件初始化完成');
    }
});

// (1).将浏览器的语言环境切换为`英文`
console.log(i18n.prop('test_username')); // Output: UserName
console.log(i18n.prop('test_password')); // Output: Password

// (2).将浏览器的语言环境切换为`中文`
console.log(i18n.prop('test_username')); // Output: 用户名
console.log(i18n.prop('test_password')); // Output: 密码