
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
Easy Lang 是一个低侵入性的、简单的、类型安全的多语言翻译工具。它本质上与框架无关,是一个纯 TypeScript 工具,可以在 Vue、React、Angular 等支持原生 JS/TS 的项目中使用。
pnpm add easy-lang
# 或
npm install easy-lang
# 或
yarn add easy-lang
Easy Lang 支持两种使用模式:扁平模式和模块化模式。你可以根据项目规模和需求选择合适的模式。
适用于小型项目或翻译文件较少的场景。
// 定义翻译文件
const translations = {
'你好': {
"zh-CN": "你好",
"en-US": "Hello",
},
'再见': {
"zh-CN": "再见",
"en-US": "Goodbye",
},
'你好 {name}': {
"zh-CN": "你好 {name}",
"en-US": "Hello {name}",
},
} as const;
// 创建翻译工具
const i18n = createI18nTool<typeof translations, "zh-CN" | "en-US">({
defaultLang: "zh-CN",
langs: ["zh-CN", "en-US"],
translations,
autoReload: false, // 切换语言时是否自动刷新页面
});
// 使用翻译
i18n.$t('你好'); // => "你好"
// 变量翻译
i18n.$t('你好 {name}', { name: 'Ell' }); // => 你好 Ell
适用于大型项目或需要按模块组织翻译的场景。
// 定义模块化翻译文件
const translations = {
default: {
'你好': {
"zh-CN": "你好",
"en-US": "Hello",
},
},
custom: {
'欢迎 {name}': {
"zh-CN": "欢迎 {name}",
"en-US": "Welcome {name}",
},
'测试': {
"zh-CN": "测试",
"en-US": "Test",
},
},
} as const;
// 创建翻译工具
const i18n = createI18nTool<typeof translations, "zh-CN" | "en-US">({
defaultLang: "zh-CN",
langs: ["zh-CN", "en-US"],
translations,
});
// 方式一:直接使用带模块的翻译
i18n.$t('欢迎 {name}', { name: '张三', module: 'custom' }); // => "欢迎 张三"
i18n.$t('测试', { module: 'custom' }); // => "测试"
// 方式二:创建模块专用的翻译函数
const $t_custom = i18n.$module('custom');
$t_custom('测试'); // => "测试"
$t_custom('欢迎 {name}', { name: 'John' }); // => "欢迎 John"
创建翻译工具的核心方法,返回一个包含以下方法和属性的对象:
interface I18nTool<T, L> {
// 核心翻译方法
$t: (text: string, contexts?: Record<string, any>, currentLang?: L) => string;
// 创建模块专用翻译函数
$module: <M extends keyof T>(module: M) => (text: string, contexts?: Record<string, any>, currentLang?: L) => string;
// 切换语言
changeLang: (lang: L) => void;
// 获取未翻译的文本列表
untranslatedList: string[];
// 支持的语言列表
langs: L[];
// 默认语言
defaultLang: L;
// 获取当前语言
getCurrentLang: () => L;
}
interface I18nCreateProps<T, L> {
// 默认语言
defaultLang: L;
// 支持的语言列表
langs: L[];
// 翻译对象
translations: T;
// 切换语言时是否自动刷新页面
autoReload?: boolean;
// 自定义 localstorage 存储的 key
storageKey?: string;
}
Easy Lang 会自动收集未翻译的文本,你可以通过 untranslatedList 获取:
console.log(i18n.untranslatedList); // 显示所有未翻译的文本列表
Easy Lang 会自动将当前语言保存在 localStorage 中:
// 切换语言(会自动保存到 localStorage)
i18n.changeLang("en-US");
// 获取当前语言
const currentLang = i18n.getCurrentLang(); // 优先从 localStorage 读取
可以配置在切换语言时自动刷新页面:
const i18n = createI18nTool({
// ...其他配置
autoReload: true, // 切换语言时自动刷新页面
});
MIT
FAQs
An easy-to-use, low-intrusion translation tool
The npm package easy-lang receives a total of 7 weekly downloads. As such, easy-lang popularity was classified as not popular.
We found that easy-lang demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.