プロパティファイル

Lingo.dev CLIによるJavaプロパティファイルのAI翻訳

プロパティファイルとは?

プロパティファイルは、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を使用してプロパティファイルを翻訳する方法を説明します。

以下の方法を学びます:

  • ゼロからプロジェクトを作成する
  • 翻訳パイプラインを設定する
  • 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. ソースコンテンツの作成

まだ作成していない場合は、翻訳するコンテンツを含むPropertiesファイルを1つ以上作成してください。これらのファイルは、パスのどこかにソースロケールを含む場所に配置する必要があります(例:ディレクトリ名として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"

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

ステップ6. LLMの設定

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

可能な限り早く始めるには、毎月10,000トークンの無料使用量を提供する当社独自のホスト型プラットフォームLingo.dev Engineの使用をお勧めします:

  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