Lewati ke konten

Terjemahan Cards

Greentic mendukung penerjemahan Adaptive Cards ke berbagai bahasa. Anda dapat memilih:

  • Satu perintah: generate --auto-translate (extract + translate + build)
  • Langkah demi langkah: extract → translate → build
Terminal window
greentic-cards2pack generate \
--cards ./cards \
--out ./my-pack \
--name my-pack \
--auto-translate \
--langs fr,de,ja

Selesai. Pack akan menyertakan assets/i18n/en.json, fr.json, de.json, ja.json.

  1. Buat card

    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. Ekstrak string yang dapat diterjemahkan

    Terminal window
    greentic-cards2pack extract-i18n \
    --input ./cards \
    --output i18n/en.json

    Output:

    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. Terjemahkan dengan greentic-i18n-translator

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

    Perintah ini membuat i18n/fr.json dan i18n/ja.json di direktori yang sama.

  4. Generate pack

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

Key yang diekstrak mengikuti pola:

{prefix}.{cardId}.{json_path}.{field}
PartSourceExample
prefixFlag --prefix (default: card)card
cardIdField greentic.cardId atau nama filewelcome
json_pathPosisi dalam struktur cardbody_0, actions_1
fieldNama fieldtext, title, label

Contoh:

  • card.welcome.body_0.text → teks TextBlock pertama
  • card.welcome.actions_0.title → title action pertama
  • card.form.body_1.placeholder → placeholder elemen body kedua
  • card.form.body_0_choices_2.title → title opsi choice ketiga

Pertahankan konsistensi nama brand dan istilah teknis di seluruh terjemahan:

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

Gunakan dengan salah satu pendekatan:

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, toggle, title fact
labelLabel input
placeholderPlaceholder input
errorMessagePesan validasi
altTextTeks alt gambar
fallbackTextKonten fallback
valueNilai fact

Dilewati secara otomatis:

  • String kosong
  • Template Handlebars murni: {{variable}}
  • Referensi variabel: ${var}
  • Pola i18n yang sudah ada: $t(key) (kecuali --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

Kegagalan terjemahan tidak fatal. Jika greentic-i18n-translator gagal untuk suatu bahasa:

  • Pack tetap berhasil di-build
  • Peringatan muncul di .cards2pack/manifest.json
  • Bundle bahasa Inggris (en.json) selalu dibuat

Cek peringatan:

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

Instal: cargo install greentic-i18n-translator

Atau atur path kustom: export GREENTIC_I18N_TRANSLATOR_BIN=/path/to/translator

Jika sebuah key tidak ada di bundle bahasa target, runtime akan fallback ke teks sumber bahasa Inggris.

Pastikan placeholder Handlebars tetap dipertahankan:

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