Xcodeの.stringsファイル

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

Xcodeの.stringsファイルとは?

Xcodeの.stringsファイルは、iOSおよびmacOSアプリケーションでローカライズされたテキストを保存するためのApple形式です。これらはコメントや特殊文字をサポートするシンプルなキーと値の形式を使用しています。

例えば:

/* 基本的な例 */
"welcome_message" = "Hello, world!";
"login_button" = "Log In";
"error_message" = "Something went wrong";

/* エスケープされた文字 */
"quote_example" = "She said \"Hello world!\"";
"newline_example" = "First line\nSecond line";

/* Unicodeと特殊文字 */
"unicode_example" = "Hello 世界 🌍";
"emoji" = "👋 Hello! 🎉";

Lingo.dev CLIとは?

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

詳細については、概要をご覧ください。

このガイドについて

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

以下の方法を学びます:

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

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

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

  1. i18n.jsonファイルのbucketsオブジェクトに"xcode-strings"オブジェクトを追加します:

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

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

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

    パターン自体は:

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

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

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

/* Basic examples */
"welcome_message" = "Hello, world!";
"login_button" = "Log In";
"error_message" = "Something went wrong";

"user_profile_title" = "User Profile";

/* Escaped characters */
"quote_example" = "She said \"Hello world!\"";
"newline_example" = "First line\nSecond line";

/* Unicode and special characters */
"unicode_example" = "Hello 世界 🌍";
"emoji" = "👋 Hello! 🎉";
"accents" = "Café, naïve, résumé";

/* Valid entries */
"settings_title" = "Settings";
"save_button" = "Save";

es/example.strings

/* Basic examples */
"welcome_message" = "¡Hola, mundo!";
"login_button" = "Iniciar Sesión";
"error_message" = "Algo salió mal";

"user_profile_title" = "Perfil de Usuario";

/* Escaped characters */
"quote_example" = "Ella dijo \"Hola mundo!\"";
"newline_example" = "Primera línea\nSegunda línea";

/* Unicode and special characters */
"unicode_example" = "Hola 世界 🌍";
"emoji" = "👋 ¡Hola! 🎉";
"accents" = "Café, naïve, résumé";

/* Valid entries */
"settings_title" = "Configuración";
"save_button" = "Guardar";

i18n.json

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

i18n.lock

version: 1
checksums:
  c0001027bc43a90fe59344ea57847e7a:
    welcome_message: 0468579ef2fbc83c9d520c2f2f1c5059
    login_button: 0029e5a35676c0051e761fcd046ef9ee
    error_message: a3cd2f01c073f1f5ff436d4b132d39cf
    user_profile_title: bee775ff7216747b2111e93cefa57ddc
    quote_example: c519c83fe2629c0e9a6e7a14f64b6317
    newline_example: ae9313a2231a16f17e2367a4e5b322ee
    backslash_example: acf69a7273edf9f932f66027f699bbbe
    mixed_escapes: 9285b600baf307f7c060e20dc5778fad
    tab_example: 1451b8323511459dac68316a2594bb82
    multiline_literal: a4c5d1c388a06e29d96833e4d2f14a26
    multiline_mixed: f5d741606567d78281bc455074eb8f6c
    multiline_with_quotes: c82ec05ec488644808917b9c958da8cc
    after_comment: b7c19db10622cb67d4dd28270e85a428
    after_multiline_comment: 759d0ffce80451996a5a45b33a0870cc
    long_value: a54e8485e571c671e35865ba72cbcaf5
    unicode_example: 2de42b1aef6d20b314928b9c2554759d
    emoji: 1b387c2b5ce6c2cd608081ebcb5e6a94
    accents: 8c054e17f9b960d9317ca110a6fedf8c
    spaces_only: 8af60e2ee58a2e1e42071066e9c225da
    many_quotes: e2ff57b8058ab2c03c5b07cf901a7a48
    missing_semicolon: b2b5f0c3f552a348188de51bd4fcf511
    settings_title: 8df6777277469c1fd88cc18dde2f1cc3
    save_button: f7a2929f33bc420195e59ac5a8bcd454