Flutter ARB
Lingo.dev CLIによるFlutter ARBファイルのAI翻訳
Flutter ARBとは?
Flutter ARB(Application Resource Bundle)は、GoogleのFlutterフレームワークでローカライズされた文字列を管理するために使用されるJSONベースの形式です。メタデータ、プレースホルダー、およびICUメッセージフォーマットをサポートし、ネイティブコンパイルされたアプリケーションの構築に対応しています。
Lingo.dev CLIとは?
Lingo.dev CLIは、AIを使用してアプリやコンテンツを翻訳するための無料のオープンソースCLIです。従来の翻訳管理ソフトウェアを置き換えるように設計されており、既存のパイプラインと統合できます。
詳細については、概要を参照してください。
このガイドについて
このガイドでは、Lingo.dev CLIを使用してFlutter ARBファイルを翻訳する方法を説明します。
以下の方法を学習します:
- ゼロからプロジェクトを作成する
- 翻訳パイプラインを設定する
- 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つ以上のARBファイルを作成します。これらのファイルは、パスのどこかにソースロケールを含む場所に配置する必要があります(例:en/のようなディレクトリ名、またはmessages.en.arbのようなファイル名の一部として)。
Flutter ARBファイルの場合、以下の要件が適用されます:
- 各メッセージキーには対応する翻訳値が必要です
- メタデータエントリ(
@で始まる)は保持されますが、翻訳されません @@localeメタデータフィールドはロケールを識別します- プレースホルダー(
{name})は翻訳中に保持されます - 複数形とセレクトのICUメッセージフォーマットがサポートされています
例:
{
"@@locale": "en",
"welcome_message": "Welcome to our Flutter app",
"@welcome_message": {
"description": "The main welcome message shown on the home screen"
},
"login_button": "Log In",
"greeting_with_name": "Hello {name}!",
"@greeting_with_name": {
"placeholders": {
"name": {
"type": "String"
}
}
}
}
ステップ5. バケットを作成する
-
i18n.jsonファイルで、bucketsオブジェクトに"flutter"オブジェクトを追加します:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "flutter": {} } } -
"flutter"オブジェクトで、1つ以上のincludeパターンの配列を定義します:{ "$schema": "https://lingo.dev/schema/i18n.json", "version": "1.10", "locale": { "source": "en", "targets": ["es"] }, "buckets": { "flutter": { "include": ["./[locale]/example.arb"] } } }これらのパターンは、翻訳するファイルを定義します。
パターン自体は:
- 設定されたロケールのプレースホルダーとして
[locale]を含む必要があります - ファイルパスを指定できます(例:
"[locale]/config.arb") - ワイルドカードプレースホルダーとしてアスタリスクを使用できます(例:
"[locale]/*.arb")
再帰的なglobパターン(例:
**/*.arb)はサポートされていません。 - 設定されたロケールのプレースホルダーとして
ステップ6. LLMを設定する
Lingo.dev CLIは、大規模言語モデル(LLM)を使用してAIでコンテンツを翻訳します。これらのモデルのいずれかを使用するには、サポートされているプロバイダーからAPIキーが必要です。
できるだけ早く開始するために、Lingo.dev Engineの使用を推奨します。これは当社がホストするプラットフォームで、毎月10,000トークンの無料利用枠を提供しています:
-
以下のコマンドを実行します:
npx lingo.dev@latest loginデフォルトのブラウザが開き、認証を求められます。
-
プロンプトに従って操作します。
ステップ7. 翻訳を生成する
i18n.jsonファイルが含まれるディレクトリで、以下のコマンドを実行します:
npx lingo.dev@latest run
このコマンドは以下を実行します:
i18n.jsonファイルを読み込みます。- 翻訳が必要なファイルを検索します。
- ファイルから翻訳可能なコンテンツを抽出します。
- 設定されたLLMを使用して抽出されたコンテンツを翻訳します。
- 翻訳されたコンテンツをファイルシステムに書き込みます。
翻訳が初めて生成される際、i18n.lockファイルが作成されます。このファイルは翻訳済みのコンテンツを追跡し、以降の実行で不要な再翻訳を防ぎます。
例
en/example.arb
{
"@@locale": "en",
"welcome_message": "Welcome to our Flutter app",
"@welcome_message": {
"description": "The main welcome message shown on the home screen",
"context": "greeting"
},
"login_button": "Log In",
"signup_button": "Sign Up",
"greeting_with_name": "Hello {name}!",
"@greeting_with_name": {
"description": "Greeting message with user's name",
"placeholders": {
"name": {
"type": "String",
"description": "The user's display name"
}
}
},
"item_count": "{count, plural, =0 {No items} one {# item} other {# items}}",
"@item_count": {
"description": "Message showing the number of items with proper pluralization",
"placeholders": {
"count": {
"type": "int",
"description": "The number of items"
}
}
}
}
es/example.arb
{
"@@locale": "es",
"welcome_message": "Bienvenido a nuestra aplicación Flutter",
"@welcome_message": {
"description": "The main welcome message shown on the home screen",
"context": "greeting"
},
"login_button": "Iniciar sesión",
"signup_button": "Registrarse",
"greeting_with_name": "¡Hola {name}!",
"@greeting_with_name": {
"description": "Greeting message with user's name",
"placeholders": {
"name": {
"type": "String",
"description": "The user's display name"
}
}
},
"item_count": "{count, plural, =0 {Sin elementos} one {# elemento} other {# elementos}}",
"@item_count": {
"description": "Message showing the number of items with proper pluralization",
"placeholders": {
"count": {
"type": "int",
"description": "The number of items"
}
}
}
}
i18n.json
{
"$schema": "https://lingo.dev/schema/i18n.json",
"version": "1.10",
"locale": {
"source": "en",
"targets": ["es"]
},
"buckets": {
"flutter": {
"include": ["./[locale]/example.arb"]
}
}
}
i18n.lock
version: 1
checksums:
88559ecadc7cff52625bd3a47e51dd78:
welcome_message: 9c56d00796c3c7facba6a25275de5b7b
login_button: 0029e5a35676c0051e761fcd046ef9ee
signup_button: 0dd2ae69be4618c1f9e615774a4509ca
error_network: e0becd5fc88e85a97c6987b96c80fb11
success_message: e6dcd73052dc41dbe05d86af9887d2c4
user_profile_title: bee775ff7216747b2111e93cefa57ddc
settings_screen_title: 8df6777277469c1fd88cc18dde2f1cc3
cancel_action: 2e2a849c2223911717de8caa2c71bade
confirm_action: 90930b51154032f119fa75c1bd422d8b
greeting_with_name: 218521f06746e82ba44d68c8a5bb210c
item_count: d8d083b56bc155cf0997ea6ae989b83f
user_status: 903b5a6edde5368dd9089accdc1b1f9d