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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@js-lion/i18n

v0.1.1

Published

国际化多语言工具

Downloads

24

Readme

@ue/i18n

国际化多语言工具

初始化

代码结构

获取文案

import i18n from "src/utils/i18n";

i18n.common.button.submit; // Submit
i18n.common.button.hello;  // hello {label}
...

方法

append

添加语言文案

import i18n from "src/utils/i18n";
const languages: object = {};
i18n.append(languages);

getLanguage

查询当前语言

import i18n from "src/utils/i18n";
const language: string = i18n.getLanguage();

setLanguage

切换语言 切换语言后, 页面已显示的文案不会自动切换, 建议刷新页面

import i18n from "src/utils/i18n";
i18n.setLanguage("language");

template

模板替换, 常用于公共文案, 进行简单的变量替换得到一个新的文案

import i18n from "src/utils/i18n";
const text = i18n.template(i18n.common.hello, { label: "world" });
// hello world

const text = i18n.template("姓名: {name}, 年龄: {age}", { name: "张三", age: 20 });
// 姓名: 张三, 年龄: 20

placeholder

同 template 一样, 在此基础上进行大小写转换, 除首字母外的字符转换为小写, 首字母大写 常用于输入框占位符提示

import i18n from "src/utils/i18n";
const text = i18n.placeholder(i18n.common.placeholder.input, { label: "name" });
// Please input name

如果需要替换的模板只有一个变量时可用

const text = i18n.placeholder(i18n.common.placeholder.input, "name");
// Please input name

rule

同 placeholder 一样, 在此基础上会在末尾添加一个感叹号, 中文时添加中文格式感叹号, 其余语言默认添加英文格式感叹号 常用于表单错误提示语

import i18n from "src/utils/i18n";
const text = i18n.rule(i18n.common.placeholder.input, { label: "name" });
// Please input name!

如果需要替换的模板只有一个变量时可用

const text = i18n.rule(i18n.common.placeholder.input, "name");
// Please input name!

part

常用在需要区分单数与复数时 中文情况

import i18n from "src/utils/i18n";
const template = "{count}个苹果";
const text = i18n.part(template, 0, { count: 0 }); // 0个苹果
const text = i18n.part(template, 1, { count: 1 }); // 1个苹果
const text = i18n.part(template, 2, { count: 2 }); // 2个苹果
const text = i18n.part(template, 3, { count: 3 }); // 3个苹果
const text = i18n.part(template, 4, { count: 4 }); // 4个苹果

英文情况

import i18n from "src/utils/i18n";
const template = "Zero apples | 1 apple | {count} apples";
const text = i18n.part(template, 0, { count: 0 }); // Zero apples
const text = i18n.part(template, 1, { count: 1 }); // 1 apple
const text = i18n.part(template, 2, { count: 2 }); // 2 apples
const text = i18n.part(template, 3, { count: 3 }); // 3 apples
const text = i18n.part(template, 4, { count: 4 }); // 4 apples