auto-i18n-updater
v1.0.3
Published
Automated i18n translation and upload library for SeaArt React Native applications
Maintainers
Readme
auto-i18n-updater
🚀 自动化国际化翻译工具
自动从 GitLab 下载 Excel 翻译文件,支持多语言处理、云存储上传和 Git 自动化。
✨ 核心功能
- 📄 GitLab 集成 - 直接下载 Excel 翻译文件
- ☁️ 云存储上传 - 可选的文件上传功能
- 🔄 Git 自动化 - 自动创建分支和合并请求
- 🛡️ 安全配置 - 环境变量管理敏感信息
🚀 快速开始
1. 安装
# 全局安装(推荐)
npm install -g auto-i18n-updater
# 或项目安装
npm install auto-i18n-updater2. 初始化配置
auto-i18n init --type react-native3. 配置环境变量
# .env 文件
GITLAB_TOKEN="your_gitlab_token"
SEAART_UPLOAD_TOKEN="your_upload_token" # 可选4. 运行
# 下载翻译文件
auto-i18n download
# 完整更新流程
auto-i18n fullupdate --create-mr⚙️ 基本配置
编辑生成的 auto-i18n.config.js 文件:
export default {
appName: 'your-app',
// GitLab 配置(必需)
gitlab: {
repositoryUrl: 'https://gitlab.com/your-org/translations',
filePath: 'translations.xlsx',
branch: 'main'
},
// 应用配置
app: {
type: 'react-native',
translationDir: 'src/locales'
},
// 功能开关
features: {
upload: true, // 启用上传
gitAutomation: true // 启用 Git 操作
},
// 令牌配置
tokens: {
gitlab: process.env.GITLAB_TOKEN,
seaartUpload: process.env.SEAART_UPLOAD_TOKEN
}
}📋 命令参考
| 命令 | 描述 |
|------|------|
| auto-i18n init | 初始化配置文件 |
| auto-i18n download | 仅下载翻译文件 |
| auto-i18n fullupdate | 完整更新流程 |
| auto-i18n fileinfo | 查看文件信息 |
| auto-i18n onlygit | 仅 Git 操作 |
常用选项
-c, --config <path>- 指定配置文件--create-mr- 创建合并请求--no-create-mr- 不创建合并请求
🔧 API 使用
import { AutoI18nUpdater, ConfigManager } from 'auto-i18n-updater'
// 加载配置
const config = await ConfigManager.load('./auto-i18n.config.js')
const updater = new AutoI18nUpdater(config)
// 下载翻译文件
const translations = await updater.runExcelDownload()
// 完整更新流程
const result = await updater.runFullUpdate({ createMR: true })📁 项目结构
your-project/
├── src/locales/ # 生成的翻译文件
│ ├── en.json
│ ├── zh.json
│ └── ...
├── ios/translations/ # iOS 翻译文件
├── android/.../translations/ # Android 翻译文件
└── auto-i18n.config.js # 配置文件🛠️ 故障排除
常见问题
下载失败
- 检查 GitLab Token 权限
- 验证仓库 URL 和文件路径
- 确认网络连接
配置错误
# 查看文件信息
auto-i18n fileinfo
# 重新初始化
auto-i18n init --type react-nativeToken 获取
- 登录 GitLab
- 设置 → Access Tokens
- 创建新令牌(需要
read_repository权限)
🔧 高级配置
export default {
app: {
type: 'react-native',
translationDir: 'src/locales',
nativeProjects: {
ios: 'ios/translations',
android: 'android/app/src/main/assets/translations'
}
}
}export default {
git: {
baseBranch: 'dev',
targetBranch: 'dev',
autoMR: true,
assignees: ['maintainer'],
labels: ['i18n']
}
}# .gitlab-ci.yml
update-translations:
script:
- npm install -g auto-i18n-updater
- auto-i18n fullupdate --create-mr
only:
- main📦 版本信息
- 版本: v1.0.1
- Node.js: >= 14.0.0
- 支持: React Native, Vue, Nuxt, React
📄 许可证
MIT License
💡 快速提示
- 🔥 首次使用: 运行
auto-i18n init开始 - 📝 配置帮助: 查看生成的配置文件注释
- 🚨 遇到问题: 运行
auto-i18n fileinfo检查连接 - 🤖 CI/CD: 使用
fullupdate --create-mr自动化
如有问题,请提交 Issue 或联系开发团队。
