YAML

Lingo.dev CLIによるYAMLファイルのAI翻訳

YAMLとは?

YAML(YAML Ain't Markup Language)は、設定ファイル、データ交換、構造化データストレージに一般的に使用される、人間が読みやすいデータシリアライゼーション形式です。階層を表現するためにインデントを使用し、複雑なデータ構造をサポートします。

例:

title: "MyApp"
description: Hello, world!
welcome_message: 'Welcome to MyApp'

user_profile:
  display_name: "John Doe"
  bio: Software developer

navigation_items:
  - "Home"
  - "About"
  - "Contact"

product:
  name: "MyWidget"
  tagline: The best widget ever

Lingo.dev CLIとは?

Lingo.dev CLIは、AIを使用してアプリやコンテンツを翻訳するための無料のオープンソースCLIです。従来の翻訳管理ソフトウェアを置き換えながら、既存のパイプラインと統合できるように設計されています。

詳細については、概要を参照してください。

このガイドについて

このガイドでは、Lingo.dev CLIを使用してYAMLファイルを翻訳する方法を説明します。

以下の方法を学習します:

  • ゼロからプロジェクトを作成する
  • 翻訳パイプラインを設定する
  • AIで翻訳を生成する

前提条件

Lingo.dev CLIを使用するには、Node.js v18以降がインストールされていることを確認してください:

❯ node -v
v22.17.0

ステップ1. プロジェクトのセットアップ

プロジェクトのディレクトリに、i18n.jsonファイルを作成します:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

このファイルは、翻訳する言語やファイルシステム上のローカライズ可能なコンテンツの場所など、翻訳パイプラインの動作を定義します。

使用可能なプロパティの詳細については、i18n.jsonを参照してください。

ステップ2. ソースロケールの設定

_ソースロケール_は、コンテンツが記述された元の言語と地域です。ソースロケールを設定するには、i18n.jsonファイルのlocale.sourceプロパティを設定します:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

ソースロケールは、BCP 47言語タグとして指定する必要があります。

Lingo.dev CLIがサポートするロケールコードの完全なリストについては、サポートされているロケールコードを参照してください。

ステップ 3. ターゲットロケールの設定

_ターゲットロケール_は、コンテンツを翻訳する言語と地域です。ターゲットロケールを設定するには、i18n.jsonファイルのlocale.targetsプロパティを設定します:

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {}
}

ステップ 4. ソースコンテンツの作成

まだ作成していない場合は、翻訳するコンテンツを含む1つ以上のYAMLファイルを作成します。これらのファイルは、パスのどこかにソースロケールを含むパスに配置する必要があります(例:en/のようなディレクトリ名、またはmessages.en.ymlのようなファイル名の一部として)。

ステップ 5. バケットの作成

  1. i18n.jsonファイルで、bucketsオブジェクトに"yaml"オブジェクトを追加します:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "yaml": {}
      }
    }
    
  2. "yaml"オブジェクトで、1つ以上のincludeパターンの配列を定義します:

    {
      "$schema": "https://lingo.dev/schema/i18n.json",
      "version": "1.10",
      "locale": {
        "source": "en",
        "targets": ["es"]
      },
      "buckets": {
        "yaml": {
          "include": ["./[locale]/example.yml"]
        }
      }
    }
    

    これらのパターンは、翻訳するファイルを定義します。

    パターン自体は:

    • 設定されたロケールのプレースホルダーとして[locale]を含む必要があります
    • ファイルパスを指定できます(例:"[locale]/config.yml")
    • ワイルドカードプレースホルダーとしてアスタリスクを使用できます(例:"[locale]/*.yml")

    再帰的なglobパターン(例:**/*.yml)はサポートされていません。

ステップ 6. LLMの設定

Lingo.dev CLIは、大規模言語モデル(LLM)を使用してAIでコンテンツを翻訳します。これらのモデルのいずれかを使用するには、サポートされているプロバイダーからAPIキーが必要です。

できるだけ早く使い始めるために、Lingo.dev Engineの使用をお勧めします。これは、毎月10,000トークンの無料利用を提供する当社独自のホスト型プラットフォームです:

  1. Lingo.devアカウントにサインアップします。

  2. 次のコマンドを実行します:

    npx lingo.dev@latest login
    

    デフォルトのブラウザが開き、認証を求められます。

  3. プロンプトに従ってください。

ステップ7. 翻訳を生成する

i18n.jsonファイルが含まれるディレクトリで、次のコマンドを実行します:

npx lingo.dev@latest run

このコマンドは:

  1. i18n.jsonファイルを読み込みます。
  2. 翻訳が必要なファイルを検索します。
  3. ファイルから翻訳可能なコンテンツを抽出します。
  4. 設定されたLLMを使用して抽出されたコンテンツを翻訳します。
  5. 翻訳されたコンテンツをファイルシステムに書き込みます。

翻訳が初めて生成されるとき、i18n.lockファイルが作成されます。このファイルは、どのコンテンツが翻訳されたかを追跡し、後続の実行で不要な再翻訳を防ぎます。

en/example.yml

title: "MyApp"
description: Hello, world!
welcome_message: 'Welcome to MyApp'

user_profile:
  display_name: "John Doe"
  bio: Software developer

navigation_items:
  - "Home"
  - "About"
  - "Contact"

product:
  name: "MyWidget"
  tagline: The best widget ever
  features:
    - "Easy to use"
    - "Fast and reliable"

settings:
  max_users: 100
  enabled: true
  timeout: 30.5

complex_structure:
  level_one:
    level_two:
      message: "Deep nested text"
locked_key_1: "This value is locked and should not be changed"
ignored_key_1: "This value is ignored and should not appear in target locales"

es/example.yml

title: "MyApp"
description: "¡Hola, mundo!"
welcome_message: "Bienvenido a MyApp"
user_profile:
  display_name: "Juan Pérez"
  bio: "Desarrollador de software"
navigation_items:
  - "Inicio"
  - "Acerca de"
  - "Contacto"
product:
  name: "MyWidget"
  tagline: "El mejor widget de todos"
  features:
    - "Fácil de usar"
    - "Rápido y confiable"
settings:
  max_users: 100
  enabled: true
  timeout: 30.5
complex_structure:
  level_one:
    level_two:
      message: "Texto anidado profundo"
locked_key_1: "This value is locked and should not be changed"

i18n.json

{
  "$schema": "https://lingo.dev/schema/i18n.json",
  "version": "1.10",
  "locale": {
    "source": "en",
    "targets": ["es"]
  },
  "buckets": {
    "yaml": {
      "include": ["./[locale]/example.yml"],
      "lockedKeys": ["locked_key_1"]
    }
  }
}

i18n.lock

version: 1
checksums:
  1b0d7c9f07dcc31a978bc337763270ea:
    title: 7dc70110429d46e3685f385bd2cc941c
    description: 0468579ef2fbc83c9d520c2f2f1c5059
    welcome_message: d1c3a9f35e377554a4ccaa467ca26614
    user_profile/display_name: febee8e9ab40b2fe5106d72675228d00
    user_profile/bio: 155ddcb7c93493ac72a37074eea0a653
    navigation_items/0: 104a3db3b671c04e167eafbe21e57881
    navigation_items/1: 944521eeeed2511833d2299931273c71
    navigation_items/2: 9afa39bc47019ee6dec6c74b6273967c
    product/name: ed21de171d538a49db999c47875f75a5
    product/tagline: b7ac41680e82d75ae7f5774f7ceef1b4
    product/features/0: c916ba887951a02793ff851853fd964f
    product/features/1: 1c60a04d6890c6ec910a7f2e6ec0ae7b
    complex_structure/level_one/level_two/message: b53034560bf657106e5aaea9160e357e