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

convert-i18n-files

v1.0.0

Published

A CLI tool to convert i18n files into multiple language files

Downloads

3

Readme

Convert I18n Files

🌍 一个强大的国际化文件转换工具,可以将单个多语言JSON文件智能转换为多个独立的语言文件。

✨ 特性

  • 🚀 智能格式检测:自动识别并支持多种JSON数据格式
  • 🌐 多语言支持:支持19种主流语言的转换
  • 📁 批量生成:一键生成所有语言的独立JSON文件
  • 🛡️ 数据验证:自动跳过无效或空值数据
  • 💻 命令行友好:简单易用的CLI接口
  • 🔧 灵活配置:支持自定义输出目录

安装

本地开发安装

# 克隆或下载项目到本地
cd convert-i18n-files

# 安装依赖
npm install

# 创建全局链接
npm link

使用方法

基本语法

convert-i18n-files convert -s <源文件路径> -o <输出目录>

参数说明

  • -s, --source <file>: 源文件路径(必需)
  • -o, --output <dir>: 输出目录(可选,默认为 dist/

示例

# 转换文件到默认目录
convert-i18n-files convert -s tableConvert.com_9s36bo.json

# 转换文件到指定目录
convert-i18n-files convert -s tableConvert.com_9s36bo.json -o dist/

# 使用完整路径
convert-i18n-files convert -s /Users/mico/Desktop/test/tableConvert.com_9s36bo.json -o dist/

🌐 支持的语言

工具支持以下19种语言,会根据源文件中的实际数据自动生成对应的语言文件:

| 语言代码 | 语言名称 | 文件名 | |---------|---------|--------| | en | 英语 (English) | en.json | | ar | 阿拉伯语 (العربية) | ar.json | | es | 西班牙语 (Español) | es.json | | fr | 法语 (Français) | fr.json | | hi | 印地语 (हिन्दी) | hi.json | | id | 印尼语 (Bahasa Indonesia) | id.json | | km | 高棉语 (ខ្មែរ) | km.json | | lo | 老挝语 (ລາວ) | lo.json | | ko | 韩语 (한국어) | ko.json | | pt | 葡萄牙语 (Português) | pt.json | | ru | 俄语 (Русский) | ru.json | | th | 泰语 (ไทย) | th.json | | tr | 土耳其语 (Türkçe) | tr.json | | vi | 越南语 (Tiếng Việt) | vi.json | | ja | 日语 (日本語) | ja.json | | zh_TW | 繁体中文 (繁體中文) | zh_TW.json | | zh_CN | 简体中文 (简体中文) | zh_CN.json | | my | 缅甸语 (မြန်မာ) | my.json | | de | 德语 (Deutsch) | de.json |

💡 智能检测:工具会自动检测源文件中包含的语言,只生成有数据的语言文件。

🔄 转换规则

处理流程

  1. 文件读取:读取并解析源JSON文件
  2. 格式检测:自动识别数据格式(对象格式或数组格式)
  3. 语言检测:扫描数据中实际包含的语言
  4. 数据过滤:跳过无效数据(null、空字符串、无key值等)
  5. 文件生成:为每种检测到的语言生成独立的JSON文件

数据处理规则

  • 有效数据:包含有效key和非空value的条目
  • 跳过条件
    • key字段为 nullundefined 或空字符串
    • value为 nullundefined
    • 数组格式中缺少key字段的条目

输出格式

生成的每个语言文件都是标准的JSON格式:

{
  "Text1": "Rules:",
  "Text2": "1. A Portion Of All Users' Bets Each Hour Is Added To The Prize Pool.",
  "Text3": "2. The Top1 User Each Hour Wins The Entire Prize Pool.",
  "Text4": "3. Players Are Ranked Based On Their Bet Amount Each Hour."
}

📄 支持的源文件格式

工具支持多种JSON数据格式,可以自动识别并正确处理:

格式1:简单键值对

适用于所有语言使用相同内容的场景:

{
  "Text1": "Rules:",
  "Text2": "1. A Portion Of All Users' Bets Each Hour Is Added To The Prize Pool.",
  "Text3": null
}

格式2:多语言对象(推荐)

适用于每种语言有不同翻译的场景:

{
  "Text1": {
    "en": "Rules:",
    "ar": "القواعد:",
    "es": "Reglas:",
    "fr": "Règles:",
    "hi": "नियम:",
    "id": "Aturan:",
    "km": "ច្បាប់:",
    "lo": "ກົດລະບຽບ:"
  },
  "Text2": {
    "en": "Game rules",
    "ar": "قواعد اللعبة",
    "es": "Reglas del juego"
  }
}

格式3:数组格式

适用于表格导出的数据,支持多种列名格式:

[
  {
    "key": "Text1",
    "source": "Rules:",
    "En_US/PK(英语)": "Rules:",
    "Ar_MECA(阿语)": "القواعد:",
    "Es_US(西班牙语)": "Reglas:"
  },
  {
    "Key": "Text2",
    "Source": "Game rules",
    "en": "Game rules",
    "ar": "قواعد اللعبة",
    "zh_CN": "游戏规则"
  }
]

📝 格式说明

| 格式 | 特点 | 适用场景 | |------|------|----------| | 简单键值对 | 所有语言使用相同内容 | 快速原型、单语言项目 | | 多语言对象 | 每种语言独立翻译 | 多语言项目(推荐) | | 数组格式 | 支持表格导出数据 | Excel/CSV转换而来的数据 |

⚠️ 重要提示

  • key字段:数组格式中必须包含 keyKey 字段作为键名
  • 空值处理:值为 nullundefined 或空字符串的条目会被自动跳过
  • 列名兼容:支持中英文列名和多种命名格式
  • 自动检测:工具会自动识别数据格式,无需手动指定

⚠️ 错误处理

工具具备完善的错误处理机制:

| 错误类型 | 错误信息 | 解决方案 | |---------|---------|----------| | 📁 文件不存在 | Source file not found | 检查文件路径是否正确 | | 📄 JSON格式错误 | Failed to parse source file | 验证JSON文件格式是否有效 | | 🔑 缺少key字段 | 数据被跳过 | 确保数组格式数据包含key字段 | | 💾 写入失败 | Failed to write file | 检查输出目录权限 |

💡 自动创建目录:如果输出目录不存在,工具会自动创建

🛠️ 开发指南

项目结构

convert-i18n-files/
├── 📁 bin/
│   └── cli.js              # 🚀 CLI入口文件
├── 📁 lib/
│   └── converter.js        # ⚙️ 核心转换逻辑
├── 📁 example/
│   ├── tableConvert.com_9s36bo copy.json  # 📋 测试数据
│   └── ...                 # 🗂️ 其他示例文件
├── 📁 dist/                # 📤 输出目录(自动生成)
├── package.json            # 📦 项目配置
└── README.md              # 📖 说明文档

核心模块说明

  • cli.js:命令行接口,处理参数解析和用户交互
  • converter.js:核心转换逻辑,包含格式检测、语言识别、数据处理等功能

本地开发

# 克隆项目
git clone <repository-url>
cd convert-i18n-files

# 安装依赖
npm install

# 创建全局链接(开发模式)
npm link

# 测试工具
convert-i18n-files convert -s example/tableConvert.com_9s36bo\ copy.json

卸载开发环境

# 移除全局链接
npm unlink -g convert-i18n-files

📄 许可证

MIT License - 详见 LICENSE 文件

🤝 贡献

欢迎提交 Issue 和 Pull Request!


Made with ❤️ by mico