キーのロック

Lingo.dev CLIを使用すると、特定の翻訳キーをロックして、すべての言語で値を同一に保つことができます。キーをロックすると、CLIはそれらを翻訳処理から除外し、ソース値をすべてのターゲットファイルに直接コピーします。

キーロックの設定

i18n.jsonのバケット設定にlockedKeysを追加します。

{
  "locale": {
    "source": "en",
    "targets": ["es", "fr", "de"]
  },
  "buckets": {
    "json": {
      "include": ["locales/[locale].json"],
      "lockedKeys": ["system/component", "config/engine", "modules/processor"]
    }
  }
}

lockedKeys配列は、ネストされたキーを指定するためにスラッシュ(/)表記を使用し、複数のキーに一致させるためにアスタリスク(*)を使用します。

キーロックの仕組み

翻訳処理中、Lingo.dev CLIは以下を実行します。

  1. ロックされたキーを識別:設定から特定
  2. 翻訳から除外:ロックされたコンテンツはAIモデルに送信されません
  3. ソース値をコピー:すべてのターゲットファイルに直接コピー
  4. 一貫性を維持:すべての言語で統一

ワークフローの例:

// locales/en.json (source)
{
  "welcome": "Welcome to our platform",
  "system": {
    "component": "Lingo.dev CLI",
    "processor": "Translation Engine"
  },
  "config": {
    "engine": "Lingo.dev Engine"
  }
}

ロックされたキーの設定:

{
  "lockedKeys": ["system/component", "system/processor", "config/engine"]
}

生成されたスペイン語翻訳:

// locales/es.json (generated)
{
  "welcome": "Bienvenido a nuestra plataforma",
  "system": {
    "component": "Lingo.dev CLI",
    "processor": "Translation Engine"
  },
  "config": {
    "engine": "Lingo.dev Engine"
  }
}

welcomeのみが翻訳され、ロックされたキーはソースと同一のままです。

キーロックがない場合、「Lingo.dev Engine」はスペイン語で「Motor de Lingo.dev」、日本語で「Lingo.devエンジン」のように誤訳される可能性がありますが、この例では望ましくありません。

ネストされたキーパス

スラッシュ(/)表記を使用して、任意の深さのキーをロックします。

{
  "lockedKeys": [
    "system/engine/component",
    "modules/ai/processor",
    "config/translation/handler"
  ]
}

この表記は、複雑なネスト構造でも機能します。

// Source structure
{
  "system": {
    "engine": {
      "component": "Lingo.dev Engine"
    }
  }
}

パスsystem/engine/componentは、コンポーネント名の値をロックします。

ドットを含むキー

スラッシュ表記は、名前にドットを含むキーを処理します。

// Source with dotted key names
{
  "modules": {
    "ai.translation": "AI Translation",
    "content.processor": "Content Processor"
  }
}

次のコマンドでこれらのキーをロックします:

{
  "lockedKeys": ["modules/ai.translation", "modules/content.processor"]
}

複数のバケットタイプ

異なるファイル形式は、異なるロックされたキーを持つことができます:

{
  "buckets": {
    "json": {
      "include": ["locales/[locale].json"],
      "lockedKeys": ["config/engine", "system/component"]
    },
    "yaml": {
      "include": ["translations/[locale].yml"],
      "lockedKeys": ["service/name", "module/title"]
    }
  }
}

各バケットタイプは、コンテンツ構造に基づいて独自のロックされたキーリストを維持します。

配列値

配列値を持つキーの場合、キー名の後に /* を追加します:

// Source file
{
  "navigation": {
    "menuItems": ["Home", "About", "Contact"],
    "title": "Main Navigation"
  }
}

次のコマンドで配列をロックします:

{
  "lockedKeys": ["navigation/menuItems/*"]
}

結果:

// locales/es.json
{
  "navigation": {
    "menuItems": ["Home", "About", "Contact"],
    "title": "Navegación Principal"
  }
}