Cards の翻訳
Greentic は、Adaptive Cards を複数の言語に翻訳することをサポートしています。方法は次の 2 つです。
- 1 コマンド:
generate --auto-translate(抽出 + 翻訳 + ビルドを実行) - ステップごと: extract → translate → build
クイックスタート(1 コマンド)
Section titled “クイックスタート(1 コマンド)”greentic-cards2pack generate \ --cards ./cards \ --out ./my-pack \ --name my-pack \ --auto-translate \ --langs fr,de,jaこれで完了です。pack には assets/i18n/en.json、fr.json、de.json、ja.json が含まれます。
ステップ別ワークフロー
Section titled “ステップ別ワークフロー”-
カードを作成する
cards/welcome.json {"type": "AdaptiveCard","version": "1.4","body": [{ "type": "TextBlock", "text": "Welcome!", "size": "Large" },{ "type": "TextBlock", "text": "How can I help you today?" }],"actions": [{ "type": "Action.Submit", "title": "Get Help" },{ "type": "Action.Submit", "title": "Contact Support" }]} -
翻訳対象の文字列を抽出する
Terminal window greentic-cards2pack extract-i18n \--input ./cards \--output i18n/en.json出力:
i18n/en.json {"card.welcome.body_0.text": "Welcome!","card.welcome.body_1.text": "How can I help you today?","card.welcome.actions_0.title": "Get Help","card.welcome.actions_1.title": "Contact Support"} -
greentic-i18n-translator で翻訳する
Terminal window greentic-i18n-translator translate \--langs fr,ja \--en i18n/en.json同じディレクトリに
i18n/fr.jsonとi18n/ja.jsonが作成されます。 -
pack を生成する
Terminal window greentic-cards2pack generate \--cards ./cards \--out ./my-pack \--name my-pack
抽出されるキーは、次のパターンに従います。
{prefix}.{cardId}.{json_path}.{field}| Part | Source | Example |
|---|---|---|
prefix | --prefix flag(デフォルト: card) | card |
cardId | greentic.cardId field または filename | welcome |
json_path | card structure 内の位置 | body_0, actions_1 |
field | field 名 | text, title, label |
例:
card.welcome.body_0.text→ 最初の TextBlock の textcard.welcome.actions_0.title→ 最初の action の titlecard.form.body_1.placeholder→ 2 番目の body 要素の placeholdercard.form.body_0_choices_2.title→ 3 番目の choice option の title
brand 名や technical term は、翻訳全体で一貫性を保ってください。
{ "Greentic": "Greentic", "Dashboard": "Dashboard", "CLI": "CLI"}どちらの方法でも使用できます。
# One commandgreentic-cards2pack generate \ --cards ./cards --out ./pack --name demo \ --auto-translate --langs fr,de \ --glossary glossary.json
# Step by stepgreentic-i18n-translator translate \ --langs fr,de \ --en i18n/en.json \ --glossary glossary.json| Field | Source Element |
|---|---|
text | TextBlock, RichTextBlock |
title | Actions, toggles, fact titles |
label | Input labels |
placeholder | Input placeholders |
errorMessage | Validation messages |
altText | Image alt text |
fallbackText | Fallback content |
value | Fact values |
自動的にスキップされるもの:
- 空文字列
- 純粋な Handlebars template:
{{variable}} - 変数参照:
${var} - 既存の i18n pattern:
$t(key)(--include-existingを指定しない限り)
Runtime 翻訳
Section titled “Runtime 翻訳”locale を設定する
Section titled “locale を設定する”i18n: default_locale: "en" locales: en: "assets/i18n/en.json" fr: "assets/i18n/fr.json" ja: "assets/i18n/ja.json"flow で locale を設定する
Section titled “flow で locale を設定する”- id: set_language type: state config: key: "locale" value: "fr" next: show_welcome
- id: show_welcome type: adaptive-card config: card: "cards/welcome" # Card text automatically resolved based on session localeエラーハンドリング
Section titled “エラーハンドリング”翻訳失敗は 致命的ではありません。greentic-i18n-translator がある言語で失敗しても、次のようになります。
- pack のビルド自体は成功する
.cards2pack/manifest.jsonに warning が記録される- 英語バンドル(
en.json)は常に作成される
warning の確認:
cat my-pack/.cards2pack/manifest.json | jq '.warnings[] | select(.kind == "translation")'トラブルシューティング
Section titled “トラブルシューティング”translator が見つからない
Section titled “translator が見つからない”auto-translation failed: failed to execute greentic-i18n-translatorインストール: cargo install greentic-i18n-translator
またはカスタムパスを設定: export GREENTIC_I18N_TRANSLATOR_BIN=/path/to/translator
Runtime で翻訳が見つからない
Section titled “Runtime で翻訳が見つからない”対象言語の bundle にキーが存在しない場合、runtime は英語の元テキストにフォールバックします。
placeholder が翻訳で失われる
Section titled “placeholder が翻訳で失われる”Handlebars placeholder が保持されていることを確認してください。
// Correct{ "card.welcome.body_0.text": "Bonjour, {{name}} !" }
// Wrong — placeholder lost{ "card.welcome.body_0.text": "Bonjour, nom !" }