You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Crowdin V1转V2 API:PowerShell示例及操作流程疑问咨询

Crowdin V1 转 V2 API 迁移指南

一、操作频率理解确认

你的理解完全正确:创建存储和添加文件属于一次性初始化操作,仅需在首次迁移或新增项目文件时执行;更新文件是日常同步操作,需要每日调用以推送最新内容。

二、PowerShell 操作示例

1. 创建存储

说明:上传本地文件到Crowdin存储,返回存储ID(后续添加/更新文件必须用到)

$projectKey = "你的API密钥"
$filePath = "本地文件路径,例如C:\translations\source.json"

$headers = @{
    "Authorization" = "Bearer $projectKey"
}

$response = Invoke-RestMethod -Uri "https://api.crowdin.com/api/v2/storages" `
    -Method Post `
    -Headers $headers `
    -InFile $filePath `
    -ContentType "application/octet-stream"

# 保存存储ID用于后续操作
Write-Host "存储ID: $($response.data.id)"

2. 添加文件

说明:将存储中的文件关联到项目,创建项目内的文件条目,返回项目文件ID(后续更新操作需要)

$projectKey = "你的API密钥"
$projectId = "你的项目ID"
$storageId = "之前创建的存储ID"
$fileName = "项目内的文件路径,例如/en/source.json"

$headers = @{
    "Authorization" = "Bearer $projectKey"
    "Content-Type" = "application/json"
}

$body = @{
    storageId = $storageId
    name = $fileName
    # 可选:按需添加directoryId、type等参数
} | ConvertTo-Json

$response = Invoke-RestMethod -Uri "https://api.crowdin.com/api/v2/projects/$projectId/files" `
    -Method Post `
    -Headers $headers `
    -Body $body

# 保存项目文件ID用于后续更新
Write-Host "项目文件ID: $($response.data.id)"

3. 更新文件

说明:每日同步本地最新文件到项目已存在的文件条目

$projectKey = "你的API密钥"
$projectId = "你的项目ID"
$fileId = "之前添加文件时返回的项目文件ID"
$filePath = "本地最新文件路径,例如C:\translations\source.json"

# 步骤1:上传新文件到存储,获取新存储ID
$storageHeaders = @{
    "Authorization" = "Bearer $projectKey"
}
$storageResponse = Invoke-RestMethod -Uri "https://api.crowdin.com/api/v2/storages" `
    -Method Post `
    -Headers $storageHeaders `
    -InFile $filePath `
    -ContentType "application/octet-stream"
$newStorageId = $storageResponse.data.id

# 步骤2:用新存储ID更新项目文件
$updateHeaders = @{
    "Authorization" = "Bearer $projectKey"
    "Content-Type" = "application/json"
}

$updateBody = @{
    storageId = $newStorageId
} | ConvertTo-Json

Invoke-RestMethod -Uri "https://api.crowdin.com/api/v2/projects/$projectId/files/$fileId" `
    -Method Patch `
    -Headers $updateHeaders `
    -Body $updateBody

Write-Host "文件更新完成"

三、关于自动创建存储的说明

目前Crowdin不会为V1 API用户自动创建存储,所有V2 API的文件操作都必须手动创建存储作为中转,这是V2 API架构的强制要求。

四、Crowdin V2 API 存储模块核心文档(中文翻译)

存储模块概述

存储是Crowdin平台用于临时存放文件的中转空间,是项目文件操作的前置环节。所有要添加到项目的文件,都必须先上传到存储,再通过存储ID关联到项目。

核心接口说明

  • 创建存储
    • 请求类型:POST
    • 地址:https://api.crowdin.com/api/v2/storages
    • 描述:上传本地文件到存储,返回存储ID。支持任意格式文件,大小限制取决于订阅方案。
  • 获取存储详情
    • 请求类型:GET
    • 地址:https://api.crowdin.com/api/v2/storages/{storageId}
    • 描述:根据存储ID查询文件信息,包括文件名、大小、上传时间等。
  • 删除存储
    • 请求类型:DELETE
    • 地址:https://api.crowdin.com/api/v2/storages/{storageId}
    • 描述:删除指定存储文件,释放空间。注意:已关联到项目文件的存储文件删除后,不影响项目内的文件内容。

内容的提问来源于stack exchange,提问作者HereToLearn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 15:57:17