コンテンツにスキップ

Cards の翻訳

Greentic は、Adaptive Cards を複数の言語に翻訳することをサポートしています。方法は次の 2 つです。

  • 1 コマンド: generate --auto-translate(抽出 + 翻訳 + ビルドを実行)
  • ステップごと: extract → translate → build

クイックスタート(1 コマンド)

Section titled “クイックスタート(1 コマンド)”
Terminal window
greentic-cards2pack generate \
--cards ./cards \
--out ./my-pack \
--name my-pack \
--auto-translate \
--langs fr,de,ja

これで完了です。pack には assets/i18n/en.jsonfr.jsonde.jsonja.json が含まれます。

  1. カードを作成する

    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" }
    ]
    }
  2. 翻訳対象の文字列を抽出する

    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"
    }
  3. greentic-i18n-translator で翻訳する

    Terminal window
    greentic-i18n-translator translate \
    --langs fr,ja \
    --en i18n/en.json

    同じディレクトリに i18n/fr.jsoni18n/ja.json が作成されます。

  4. pack を生成する

    Terminal window
    greentic-cards2pack generate \
    --cards ./cards \
    --out ./my-pack \
    --name my-pack

抽出されるキーは、次のパターンに従います。

{prefix}.{cardId}.{json_path}.{field}
PartSourceExample
prefix--prefix flag(デフォルト: cardcard
cardIdgreentic.cardId field または filenamewelcome
json_pathcard structure 内の位置body_0, actions_1
fieldfield 名text, title, label

例:

  • card.welcome.body_0.text → 最初の TextBlock の text
  • card.welcome.actions_0.title → 最初の action の title
  • card.form.body_1.placeholder → 2 番目の body 要素の placeholder
  • card.form.body_0_choices_2.title → 3 番目の choice option の title

brand 名や technical term は、翻訳全体で一貫性を保ってください。

glossary.json
{
"Greentic": "Greentic",
"Dashboard": "Dashboard",
"CLI": "CLI"
}

どちらの方法でも使用できます。

Terminal window
# One command
greentic-cards2pack generate \
--cards ./cards --out ./pack --name demo \
--auto-translate --langs fr,de \
--glossary glossary.json
# Step by step
greentic-i18n-translator translate \
--langs fr,de \
--en i18n/en.json \
--glossary glossary.json
FieldSource Element
textTextBlock, RichTextBlock
titleActions, toggles, fact titles
labelInput labels
placeholderInput placeholders
errorMessageValidation messages
altTextImage alt text
fallbackTextFallback content
valueFact values

自動的にスキップされるもの:

  • 空文字列
  • 純粋な Handlebars template: {{variable}}
  • 変数参照: ${var}
  • 既存の i18n pattern: $t(key)--include-existing を指定しない限り)
greentic.demo.yaml
i18n:
default_locale: "en"
locales:
en: "assets/i18n/en.json"
fr: "assets/i18n/fr.json"
ja: "assets/i18n/ja.json"
- 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

翻訳失敗は 致命的ではありませんgreentic-i18n-translator がある言語で失敗しても、次のようになります。

  • pack のビルド自体は成功する
  • .cards2pack/manifest.json に warning が記録される
  • 英語バンドル(en.json)は常に作成される

warning の確認:

Terminal window
cat my-pack/.cards2pack/manifest.json | jq '.warnings[] | select(.kind == "translation")'
auto-translation failed: failed to execute greentic-i18n-translator

インストール: cargo install greentic-i18n-translator

またはカスタムパスを設定: export GREENTIC_I18N_TRANSLATOR_BIN=/path/to/translator

対象言語の bundle にキーが存在しない場合、runtime は英語の元テキストにフォールバックします。

Handlebars placeholder が保持されていることを確認してください。

// Correct
{ "card.welcome.body_0.text": "Bonjour, {{name}} !" }
// Wrong — placeholder lost
{ "card.welcome.body_0.text": "Bonjour, nom !" }