Lingo.dev + .strings (Xcode)

Lingo.dev CLIはXcodeの.stringsファイルをキーと値の構造、コメント、およびiOSのローカリゼーション規則を保持しながら翻訳します。このCLIは古いXcodeプロジェクトやワークフローにも対応し、コメント内の開発者コンテキストと指示を維持し、%@%dなどのiOSフォーマット指定子を保持し、UTF-16およびUTF-8エンコーディングを適切に処理し、標準的なiOSローカリゼーションパイプラインと統合します。

クイックセットアップ

レガシーXcode stringsファイル用の設定:

{
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de", "ja"]
  },
  "buckets": {
    "xcode-strings": {
      "include": ["Resources/[locale].lproj/Localizable.strings"]
    }
  }
}

注意: [locale]は設定内でそのまま残しておくべきプレースホルダーであり、CLI実行時に実際のロケールに置き換えられます。

stringsファイルの翻訳

npx lingo.dev@latest i18n

値を翻訳しながら、stringsファイル形式、開発者コメント、およびiOS固有の規則を保持します。

stringsファイルの構造

基本的なキーと値のペア

/* メインナビゲーション */
"nav.home" = "Home";
"nav.settings" = "Settings";
"nav.profile" = "Profile";

/* 認証 */
"auth.login" = "Log In";
"auth.logout" = "Log Out";
"auth.register" = "Sign Up";

フォーマット指定子

/* プレースホルダー付きユーザーメッセージ */
"welcome.user" = "Welcome back, %@!";
"items.count" = "You have %d items in your cart";
"download.progress" = "Downloading... %.1f%% complete";

複数行の文字列

/* 長いコンテンツ */
"terms.agreement" = "By using this app, you agree to our terms of service and privacy policy. Please read them carefully before proceeding.";

"help.description" = "This feature helps you manage your tasks efficiently. You can create, edit, and organize your work items.";

iOS固有の機能

ローカリゼーションコメント

/* 下部のタブバーに表示されます */
"tab.home" = "ホーム";

/* フォーム送信ボタンのテキスト */
"button.submit" = "送信";

/* ネットワークが利用できない場合のエラーメッセージ */
"error.network" = "インターネット接続を確認してください";

開発者コメントは翻訳者にコンテキストを提供します。

特殊文字

/* 引用符と特殊文字を含む文字列 */
"message.quote" = "彼女は\"こんにちは!\"と言いました";
"path.file" = "Documents\\MyFile.txt";
"symbol.copyright" = "© 2024 Company Name";

引用符とバックスラッシュの適切なエスケープが保持されます。

ストーリーボード連携

/* ストーリーボードのローカリゼーション */
"A8K-3L-9X7.text" = "ようこそ";
"B9M-4N-0Y8.placeholder" = "お名前を入力してください";
"C0P-5Q-1Z9.title" = "設定";

Interface Builderで生成されたキーが正しく処理されます。

高度な設定

複数のStringsファイル

"xcode-strings": {
  "include": [
    "Resources/[locale].lproj/Localizable.strings",
    "Resources/[locale].lproj/InfoPlist.strings"
  ]
}

システムキーのロック

"xcode-strings": {
  "include": ["Resources/[locale].lproj/Localizable.strings"],
  "lockedKeys": ["CFBundleName", "CFBundleDisplayName"]
}