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. バケットの作成
-
i18n.jsonファイルのbucketsオブジェクトに"yaml"オブジェクトを追加します:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "yaml": {} } } -
"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")
再帰的なグロブパターン(例:
**/*.yml)はサポートされていません。 - 設定されたロケールのプレースホルダーとして
ステップ6. LLMの設定
Lingo.dev CLIは、AIでコンテンツを翻訳するために大規模言語モデル(LLM)を使用します。これらのモデルを使用するには、サポートされているプロバイダーからAPIキーが必要です。
可能な限り早く始めるには、毎月10,000トークンの無料使用量を提供する当社独自のホスト型プラットフォームLingo.dev Engineの使用をお勧めします:
-
Lingo.devアカウントにサインアップしてください。
-
次のコマンドを実行します:
npx lingo.dev@latest loginこれにより、デフォルトのブラウザが開き、認証を求められます。
-
画面の指示に従ってください。
ステップ 7. 翻訳を生成する
i18n.jsonファイルが含まれているディレクトリで、次のコマンドを実行します:
npx lingo.dev@latest run
このコマンドは以下を実行します:
i18n.jsonファイルを読み込みます。- 翻訳が必要なファイルを見つけます。
- ファイルから翻訳可能なコンテンツを抽出します。
- 設定されたLLMを使用して抽出されたコンテンツを翻訳します。
- 翻訳されたコンテンツをファイルシステムに書き戻します。
翻訳が初めて生成される際に、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