Propertiesファイル

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

Propertiesファイルとは?

Propertiesファイルは、Javaアプリケーションで設定やローカライゼーションに一般的に使用されるシンプルなキーバリュー形式のテキストファイルです。

例:

app.title=MyApp
app.description=A simple demo application

user.greeting=Hello, world!
user.farewell=Thanks for using MyApp

error.message=Something went wrong
error.notFound=Page not found

Lingo.dev CLIとは?

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

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

このガイドについて

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

以下の内容を学習します:

  • ゼロからプロジェクトを作成する
  • 翻訳パイプラインを設定する
  • 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つ以上のPropertiesファイルを作成します。これらのファイルは、パスのどこかにソースロケールを含む場所に配置する必要があります(例:en/のようなディレクトリ名、またはmessages.en.propertiesのようなファイル名の一部として)。

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

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

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

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

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

    パターン自体は:

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

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

ステップ 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.properties

app.title=MyApp
app.description=A simple demo application

user.greeting=Hello, world!
user.farewell=Thanks for using MyApp

error.message=Something went wrong
error.notFound=Page not found

database.host=localhost
database.port=5432

notification.success=Changes saved!
notification.warning=Please check your input

es/example.properties

app.title=MyApp
app.description=Una aplicación de demostración simple

user.greeting=¡Hola, mundo!
user.farewell=Gracias por usar MyApp

error.message=Algo salió mal
error.notFound=Página no encontrada

database.host=localhost
database.port=5432

notification.success=¡Cambios guardados!
notification.warning=Por favor verifica tu entrada

i18n.json

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

i18n.lock

version: 1
checksums:
  2250baa513dddb2c691cb62115d5e257:
    app.title: 7dc70110429d46e3685f385bd2cc941c
    app.description: e13baa1e885129d9328e216ff534761b
    user.greeting: 0468579ef2fbc83c9d520c2f2f1c5059
    user.farewell: 118794a2b84f7bfb4b4ce602ed463b0f
    error.message: a3cd2f01c073f1f5ff436d4b132d39cf
    error.notFound: 97612e6230bc7a1ebd99380bf561b732
    database.host: da86e4fc0c04d82c87006dc71cea7e97
    notification.success: 3b7a8b0aa23977592d4270ea136a390c
    notification.warning: c38895f731311cefacee9e8d7d10fc49