什麼是motaword CLI?
motaword CLI是一個命令行工具,允許開發者和管理員直接與MotaWord翻譯平臺交互。它提供了從文件上傳翻譯到報告生成等完整工作流的管理能力,特別適合集成到開發環境和CI/CD流程中。如何使用motaword CLI?
通過簡單的命令行指令即可管理翻譯項目,主要步驟包括:1) 安裝CLI工具 2) 配置認證 3) 使用特定命令管理翻譯工作流。適用場景
適合需要持續本地化的軟件開發團隊、多語言內容管理系統以及自動化翻譯流程集成。主要功能
優勢與侷限性
如何使用
使用案例
常見問題
相關資源
🚀 motaword CLI
使用 MotaWord CLI 可以通過多種方式與你的 MotaWord 賬戶進行交互,從而管理你的翻譯和本地化需求。
🚀 快速開始
若要在本地搭建並運行,請按照以下簡單步驟操作。
📦 下載預構建二進制文件
使用此 GitHub 倉庫中的“發佈”功能,為你的相應平臺下載應用程序。我們會發布適用於 Linux、Windows 和 MacOS 多種配置的 motaword
。
下載地址:發佈版本
📦 通過 bash 安裝程序安裝
我們提供了一個 installer.sh
bash 腳本,你可以使用 curl
來在你的工作目錄中安裝最新版本的 motaword
CLI。你可以在這個倉庫中找到 installer.sh
腳本。
你可以通過運行以下命令來安裝 motaword
:
curl -s https://raw.githubusercontent.com/motaword/cli/master/installer.sh | bash
📦 通過 Homebrew 安裝
Mac 用戶可以通過 Homebrew 輕鬆安裝 motaword
:
- 點擊以下命令:
brew tap motaword/homebrew-tap
- 安裝
motaword
:
brew install motaword
現在你可以在系統的任何位置運行 motaword
。
✨ 主要特性
motaword
允許你訪問 MotaWord 平臺的各個方面,從提交文件進行翻譯到獲取報告,從管理你的術語表到樣式指南。
💻 使用示例
基礎用法
命令類別/父命令
要查看 motaword
支持的所有命令,請運行:
> motaword help
Usage:
motaword [command]
Available Commands:
async Manage async operations
auth Authentication settings
continuous-projects Manage your continuous projects
debug Debug your MotaWord configuration and environment
documents Manage documents
get-access-token Retrieve an access token to interact with the API.
glossaries Manage glossaries
help Help about any command
help-config Show CLI configuration help
help-input Show CLI input help
projects Manage projects
reports Manage reports
search Manage search operations
static Manage static endpoints
stats Manage stats
strings Manage strings
styleguides Manage styleguides
translate Instantly translate your content with your existing TM and MT resources. This is an alias to `continuous-projects translate`
users Manage users
webhooks Manage webhooks
Flags:
-h, --help help for motaword
-o, --output-format string Output format [json, yaml] (default "json")
--profile string Credentials profile to use for authentication (default "default")
-q, --query string Filter / project results using JMESPath
--raw Output result as raw rather than pretty JSON
--server string Override server URL
--v Enable WARN level verbose log output
--verbose Enable DEBUG level verbose log output, same as --vvv flag
--vv Enable INFO level verbose log output
--vvv Enable DEBUG level verbose log output
Additional help topics:
motaword blog Manage blog articles
motaword clients Manage client account
motaword token Manage token operations
Use "motaword [command] --help" for more information about a command.
這些是命令類別,每個類別下還有子命令。
子命令
假設我們想獲取有關我的賬戶的一些報告:
> motaword reports
Usage:
motaword reports [command]
Available Commands:
get-language-pairs-report Returns a report of language pairs.
get-projects-report Returns a report of corporate account users.
get-users-report Returns a report of corporate account users.
現在我們看到了 reports
類別下的可用命令。讓我們使用 get-language-pairs-report
子命令:
> motaword reports get-language-pairs-report
{
"meta": {
"paging": {
"links": {
"next": null,
"previous": null,
"self": {
"href": "https://api.staging.motaword.com/v0/reports/language-pairs"
}
},
"page": 1,
"per_page": 2,
"total_count": 2
}
},
"report": [
{
"language_pair": {
"source_language": "af",
"target_language": "ak"
},
"spending": "343.42",
"word_count": "2475"
},
{
"language_pair": {
"source_language": "en-US",
"target_language": "fr"
},
"spending": "11.70",
"word_count": "195"
}
]
}
大多數命令將返回 JSON 響應。通過使用像 jq
這樣的工具,你可以處理這些 JSON 響應。以下是一個從上述響應中獲取人類可讀輸出的示例:
> motaword reports get-language-pairs-report \
| jq '.report[] | "For \(.language_pair.source_language) into \(.language_pair.target_language), we spent $\(.spending)"'
"For af into ak, we spent $343.42"
"For en-US into fr, we spent $11.70"
命令參數
一些命令接受參數和 JSON 有效負載。我們可以使用 --help
標誌來查看它們可以接受哪種參數或 JSON 有效負載。
> motaword projects get-project --help
Get single project
Usage:
motaword projects get-project id [flags]
Flags:
-h, --help help for get-project
--with[] string Include detailed information. Possible values 'client', 'vendor', 'score'
get-project
命令僅接受 id
參數和 with[]
標誌。
一些命令將接受 JSON 有效負載,這些通常是創建/更新命令(例如 HTTP 中的 POST/PUT 請求)。
我們可以通過 --help
查看請求有效負載的格式。請求描述是一個 OpenAPI 規範。以下是一個示例(為簡潔起見,刪除了描述):
> motaword reports get-projects-report --help
## Request Schema (application/json)
properties:
budget_code:
type: string
date_from:
format: date-time
type: string
date_to:
format: date-time
type: string
source_languages:
items:
type: string
type: array
target_languages:
items:
type: string
type: array
users:
items:
format: int64
type: integer
type: array
type: object
Usage:
motaword reports get-projects-report [flags]
Flags:
-h, --help help for get-projects-report
根據幫助輸出中的請求模式,你可以使用此命令發送此有效負載(這將生成這些日期內的項目報告):
{
"date_from":"2021-04-21T16:07:12.727Z",
"date_to":"2021-05-21T16:07:12.727Z"
}
發送 JSON 有效負載
像上面這樣的 JSON 有效負載可以通過將 STDIN
管道傳輸到命令來發送。
如果你有一個簡單的有效負載,你可以這樣做:
> echo '{"date_from":"2021-05-21T16:07:12.727Z","date_to":"2021-05-21T16:07:12.727Z"}' \
| motaword reports get-projects-report
如果你有一個更復雜的有效負載,我們建議先將其放在一個文件中,然後將文件管道傳輸到命令:
> motaword reports get-projects-report < my-complex-payload.json
📚 詳細文檔
配置
motaword
CLI 應用程序會查找 .motaword/
目錄來進行自我配置。它按以下順序查找配置:
- 工作目錄
$HOME/.motaword
/etc/.motaword
我們在這個目錄中保存兩個文件:
credentials.json
config.json
credentials.json
保存你的 MotaWord API 客戶端 ID 和客戶端密鑰。這個文件可以通過 motaword
CLI 本身生成。有關更多信息,請參閱下面的身份驗證部分。
config.json
允許你配置 motaword
CLI 的各個方面,尤其適用於通常在開發和 CI/CD 環境中使用的 motaword translate
命令。你可以在下面瞭解更多關於 translate
命令的信息。
除非你使用 translate
命令,否則 config.json
文件是可選的。
身份驗證
簡而言之
添加默認身份驗證配置文件以自動創建 .motaword/credentials.json
:
motaword auth add-profile client-credentials default MY-CLIENT-ID MY-CLIENT-SECRET
身份驗證詳情
motaword
CLI 需要一個 MotaWord 開發者賬戶和一個 API 客戶端(我們稱之為“應用”)。你可以在這裡創建一個:https://www.motaword.com/developer
一旦你有了一個開發者賬戶,就在你的開發者門戶上創建一個新應用。現在你可以訪問這個應用的 API 客戶端 ID 和密鑰。
你需要將這些密鑰放在 .motaword/credentials.json
文件中,並與你的 motaword
CLI 一起使用。credentials.json
文件看起來是這樣的:
{
"profiles": {
"default": {
"client_id": "my-client-id",
"client_secret": "my-client-secret",
"type": "client-credentials"
}
}
}
motaword
CLI 允許你有多個身份驗證配置文件。在大多數用例中,default
配置文件就足夠了,但你可以有多個具有任意名稱的配置文件(例如,在上面的示例中,用 secondary-profile
代替 default
)。
我們提供了一種自動管理身份驗證配置文件的方法:
> motaword auth
Authentication settings
Usage:
motaword auth [command]
Available Commands:
add-profile Add user profile for authentication
list-profiles List available configured authentication profiles
Flags:
-h, --help help for auth
你可以使用以下命令添加一個配置文件:
> motaword auth add-profile client-credentials <name> <client-id> <client-secret>
讓我們添加一個默認配置文件:
motaword auth add-profile client-credentials default my-client-id my-client-secret
就是這樣!motaword
CLI 將為你管理身份驗證,包括重用和刷新你的 API 訪問令牌。
翻譯
不用說,翻譯你的文件是我們的 CLI 工具最重要的功能。你可以使用任何文檔上傳、項目下載/打包命令,但是,有一個獨家命令可以為你解決所有問題:
> motaword translate --help
Usage:
motaword translate [target-language] [flags]
Flags:
-h, --help help for translate
這個命令比它看起來要智能得多,並且有自己的一組配置來處理你的文件翻譯。這在代碼庫和 CI/CD 環境中特別有用。
它到底做了什麼?
它上傳你的語言資源文件,下載翻譯後的版本,並將它們放在你的目錄結構中的正確位置。讓我們深入瞭解一下。
配置翻譯
translate
命令帶有高度靈活的配置,以支持所有用例中的翻譯。讓我們來看看這些配置:
配置鍵 | 類型 | 是否必需 | 默認值 | 描述 |
---|---|---|---|---|
project-id | 整數或字符串 | 是 | null |
這是 MotaWord 為你提供的連續項目 ID。 |
source-directory | 字符串 | 是 | null |
motaword CLI 開始查找源文件的基本目錄。實際的源文件檢測可以通過 rules 配置進行管理。所有規則都基於這個源目錄。 |
translations-directory | 字符串 | 否 | source-directory /{locale} |
motaword CLI 開始放置翻譯文件的基本目錄。翻譯文件模式的 rules 配置將基於這個目錄。可以與 source-directory 相同。默認情況下,我們將翻譯文件放在 source-directory 下的每個 {locale} 目錄中。注意,默認值可能不是你實際情況中的正確方式。 |
rules | JSON 映射 {string: string} |
是 | { "**/*" : "{path}/{basename}" } |
類似 glob 的文件路徑模式列表,用於指定源文件以及如何放置它們的翻譯版本。有關更多可用變量、詳細解釋和示例,請參見下文。 |
exclude-rules | JSON 數組 [string] | 否 | [] | 類似 glob 的排除源文件模式列表。我們在翻譯期間將跳過這些文件。 |
翻譯規則
rules
配置非常靈活,可以在許多用例中實現正確的目錄結構。每個規則使用類似 glob
的路徑模式來收集源文件列表。你可以指定多個規則,將不同的目錄結構組合到你的 MotaWord 翻譯中。
讓我們看看 rules
的默認值:
{
"source-directory": "src/en",
"translations-directory": "src/{locale}",
"rules": {
"**/*": "{path}/{basename}"
}
}
這個規則告訴 motaword
CLI:
將
src/en
目錄中的所有文件作為源文件,並將它們的翻譯文件放在src/{locale}
目錄中的相同路徑結構中,其中{locale}
是你的每種翻譯語言。
如果你的源目錄和翻譯目錄的組織方式很簡單,這可能就足夠了。然而,規則可以處理非常複雜的用例。讓我們看一個比默認規則稍微複雜一點的例子:
在看這個複雜的例子之前,你應該先看一下規則中的可用變量部分,這會讓例子更容易理解。
{
"source-directory": "src/main/resources/strings",
"translations-directory": "src/main/resources/translations",
"rules": {
"frontend/json/*.json": "{locale}/{path}/{basename}",
"frontend/**/*.yml": "{locale}/{path}/{filename}.yaml",
"pot/*.pot": "{locale}/{path}/{basename}",
"md/*.md": "markdown-translations/{locale}/{path}/{filename}.md"
},
"exclude-rules": [
"pot/passwords*"
]
}
像這樣的 rules
配置說明了很多事情 :)
要調試和理解你的規則說明了什麼,你可以隨時運行 motaword debug
。它將輸出檢測到的源文件及其對應的翻譯路徑。
讓我們來分析一下上面的複雜規則:
假設我們要將文件翻譯成法語,其語言代碼為
fr
- 將
src/main/resources/strings
作為源文件的基本目錄。 - 將
src/main/resources/translations
作為翻譯文件的基本目錄。最後一個文件夾與源路徑不同。 - 翻譯
src/main/resources/strings/frontend/json/
目錄中的所有.json
文件,不遞歸到子目錄- 並將它們的(例如法語)翻譯文件放入
src/main/resources/translations/fr/frontend/json/
目錄中。
- 並將它們的(例如法語)翻譯文件放入
- 翻譯
src/main/resources/strings/frontend/
目錄下的所有.yml
文件,遞歸到所有子目錄- 並將它們的(例如法語)翻譯文件放在
src/main/resources/translations/fr/
目錄下,使用源文件的相應相對路徑。
- 並將它們的(例如法語)翻譯文件放在
- 翻譯
src/main/resources/strings/md/
目錄中的所有.md
文件,不遞歸到子目錄- 並將它們的(例如法語)翻譯文件放入
src/main/resources/translations/fr/md/
目錄中。
- 並將它們的(例如法語)翻譯文件放入
- 最後,在執行所有這些操作時,排除
src/main/resources/strings/pot
目錄中文件名以passwords
開頭的所有文件。
如果你還在閱讀,那麼你就是一位 motaword
配置專家了 :)
規則中的可用變量
變量 | 描述 | 示例 |
---|---|---|
{basename} |
文件的全名,包括文件擴展名 | 如果源目錄是:./source-directory 給定: ./source-directory/json-files/ui.json 則 {basename} 為:ui.json |
{filename} |
文件名,不包括文件擴展名。 這個變量通常用於更改翻譯文件的擴展名。 |
如果源目錄是:./source-directory 給定: ./source-directory/json-files/ui.json 則 {filename} 為:ui |
{path} |
從源目錄到文件的目錄路徑。 這是修改目錄結構最有用的變量。 |
如果源目錄是:./source-directory 給定: ./source-directory/json-files/v1/public/ui.json 則 {path} 為:json-files/v1/public |
{locale} |
正在處理的翻譯語言代碼。 當你的翻譯目錄對目標語言目錄有不同需求時,這個變量最有用。 |
en-US 、fr 、zh-CN 等... |
翻譯配置示例
查看此倉庫中的 ./examples
目錄,獲取各種配置示例。
調試
所有 motaword
CLI 命令都可以使用一些調試標誌。使用 --help
查看這些標誌。
你可以使用詳細標誌來配置輸出級別:
標誌 | 日誌級別 |
---|---|
--v |
警告級別日誌 |
--vv |
信息級別日誌 |
--vvv 或 --verbose |
調試級別日誌 |
還有一個 debug
命令可用於你的 config.json
配置文件:
> motaword debug
這將輸出檢測到的源文件及其對應的翻譯路徑。
📄 許可證
文檔未提及此項目的許可證信息。
📞 聯繫我們
提供 24/7 免費技術或業務即時聊天支持:https://www.motaword.com













