{"id":29322405,"url":"https://github.com/2ue/i18n","last_synced_at":"2025-07-07T14:13:11.725Z","repository":{"id":301515784,"uuid":"1009480582","full_name":"2ue/i18n","owner":"2ue","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-27T08:12:02.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-27T09:24:19.952Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2ue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-27T07:47:01.000Z","updated_at":"2025-06-27T08:12:05.000Z","dependencies_parsed_at":"2025-06-27T09:34:31.163Z","dependency_job_id":null,"html_url":"https://github.com/2ue/i18n","commit_stats":null,"previous_names":["2ue/i18n"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2ue/i18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fi18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fi18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fi18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fi18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2ue","download_url":"https://codeload.github.com/2ue/i18n/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fi18n/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264089886,"owners_count":23555819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-07T14:13:08.527Z","updated_at":"2025-07-07T14:13:11.716Z","avatar_url":"https://github.com/2ue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i18n-xy\n\n国际化提取替换翻译工具，用于扫描项目中的中文文案，提取并替换为国际化函数（如`$t('key')`），同时生成对应的多语言JSON文件。\n\n[![npm version](https://img.shields.io/npm/v/i18n-xy.svg)](https://www.npmjs.com/package/i18n-xy)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yourusername/i18n-xy/blob/main/LICENSE)\n\n## 功能特点\n\n- 🔍 **智能扫描**：自动扫描项目中的中文文案，支持js/jsx/ts/tsx文件\n- 🔑 **自动提取**：提取中文文案并生成唯一key，支持拼音和哈希两种模式\n- 🔄 **自动替换**：将中文替换为国际化函数调用，如`$t('key')`\n- 📦 **自动导入**：根据配置自动导入国际化函数\n- 📝 **多语言生成**：生成多语言JSON文件，支持多种语言\n- 🌐 **自动翻译**：支持百度翻译API自动翻译\n- ⚙️ **高度可配置**：提供丰富的配置选项，满足不同项目需求\n\n## 安装\n\n```bash\n# 全局安装\nnpm install i18n-xy --global\n\n# 或使用pnpm\npnpm add i18n-xy --global\n\n# 项目内安装\nnpm install i18n-xy --save-dev\n\n# 或使用pnpm\npnpm add i18n-xy --save-dev\n```\n\n## 快速开始\n\n### 步骤1: 初始化配置\n\n```bash\n# 生成默认配置文件\ni18n-xy init\n```\n\n这将在项目根目录创建`i18n-xy.config.ts`文件。\n\n### 步骤2: 提取中文文案\n\n```bash\n# 扫描并提取中文文案\ni18n-xy extract\n```\n\n这将扫描项目中的文件，提取中文文案，并生成语言文件。\n\n### 步骤3: 替换中文文案\n\n```bash\n# 替换中文文案为国际化函数调用\ni18n-xy replace\n```\n\n这将替换项目中的中文文案为国际化函数调用。\n\n### 步骤4: 翻译文案（可选）\n\n```bash\n# 翻译中文文案到其他语言\ni18n-xy translate --locale en,ja\n```\n\n这将翻译中文文案到英语和日语。\n\n## 命令行选项\n\n### 全局选项\n\n- `-c, --config \u003cpath\u003e` - 指定配置文件路径\n- `-d, --debug` - 启用调试模式\n- `-v, --verbose` - 显示详细输出\n- `--help` - 显示帮助信息\n- `--version` - 显示版本信息\n\n### init 命令\n\n初始化配置文件。\n\n```bash\ni18n-xy init [options]\n```\n\n选项:\n- `-o, --output \u003cpath\u003e` - 指定配置文件输出路径，默认为`./i18n-xy.config.ts`\n- `-f, --force` - 强制覆盖已存在的配置文件\n\n### extract 命令\n\n提取中文文案。\n\n```bash\ni18n-xy extract [options]\n```\n\n选项:\n- `-o, --output \u003cpath\u003e` - 指定输出目录\n- `--dry-run` - 仅扫描不写入文件\n- `--pattern \u003cpattern\u003e` - 指定文件匹配模式\n- `--ignore \u003cpattern\u003e` - 指定忽略文件模式\n- `--replace` - 提取的同时替换中文文案\n\n### replace 命令\n\n替换中文文案为国际化函数调用。\n\n```bash\ni18n-xy replace [options]\n```\n\n选项:\n- `--dry-run` - 仅扫描不写入文件\n- `--pattern \u003cpattern\u003e` - 指定文件匹配模式\n- `--ignore \u003cpattern\u003e` - 指定忽略文件模式\n- `--auto-import` - 自动导入国际化函数\n\n### translate 命令\n\n翻译中文文案到其他语言。\n\n```bash\ni18n-xy translate [options]\n```\n\n选项:\n- `--locale \u003clocales\u003e` - 指定目标语言，多个语言用逗号分隔\n- `--dry-run` - 仅扫描不写入文件\n- `-o, --output \u003cpath\u003e` - 指定输出目录\n\n## 配置文件\n\ni18n-xy使用配置文件来控制其行为。默认配置文件名为`i18n-xy.config.ts`，也支持`.js`和`.json`格式。\n\n配置文件示例:\n\n```typescript\nimport { Config } from 'i18n-xy';\n\nconst config: Config = {\n  locale: 'zh-CN',\n  fallbackLocale: 'en-US',\n  outputDir: 'locales',\n  include: ['src/**/*.{js,jsx,ts,tsx}'],\n  exclude: ['node_modules/**'],\n  keyGeneration: {\n    maxChineseLength: 8,\n    hashLength: 6,\n    reuseExistingKey: true,\n    duplicateKeySuffix: 'hash',\n    keyPrefix: '',\n    separator: '_',\n    maxRetryCount: 5,\n    pinyinOptions: {\n      toneType: 'none',\n      type: 'array'\n    }\n  },\n  output: {\n    prettyJson: true,\n    localeFileName: '{locale}.json'\n  },\n  replacement: {\n    functionName: '$t',\n    autoImport: {\n      enabled: true,\n      insertPosition: 'afterImports',\n      imports: {\n        '**/*.{jsx,tsx}': {\n          importStatement: \"import { useTranslation } from 'react-i18next';\\nconst { t: $t } = useTranslation();\"\n        }\n      }\n    }\n  }\n};\n\nexport default config;\n```\n\n详细配置选项请参考[配置文档](./docs/config.md)。\n\n## 使用示例\n\n详细使用示例请查看[使用指南](./docs/guide.md)和[示例目录](./examples)。\n\n## 支持的场景\n\ni18n-xy支持多种中文文案提取和替换场景，包括但不限于：\n\n- 字符串字面量（单引号、双引号）\n- 模板字符串（包括嵌套模板）\n- JSX文本节点\n- JSX属性值\n- 对象和数组中的中文字符串\n- 条件表达式中的中文字符串\n- 函数参数中的中文字符串\n\n详细支持的场景请参考[场景文档](./docs/scenarios.md)。\n\n## 开发\n\n```bash\n# 克隆仓库\ngit clone https://github.com/yourusername/i18n-xy.git\ncd i18n-xy\n\n# 安装依赖\npnpm install\n\n# 开发模式\npnpm dev\n\n# 构建\npnpm build\n\n# 测试\npnpm test\n```\n\n## 贡献指南\n\n欢迎贡献代码、报告问题或提出建议！请参考[贡献指南](./CONTRIBUTING.md)。\n\n## 变更日志\n\n查看[变更日志](./CHANGELOG.md)了解各版本的变化。\n\n## 许可证\n\n[MIT](./LICENSE) ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fi18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2ue%2Fi18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fi18n/lists"}